on 06-15-2009 8:30 AM
Hi All,
How can i validate the given data is string or not
Hi ep Bhargava,
String strValidChars =
"0123456789";
char strChar;
boolean blnResult = true;
if (inputValue.length() == 0)
return false;
for (int i = 0; i < inputValue.length() && blnResult == true; i++)
{
strChar = inputValue.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
blnResult = false;
}
}
return blnResult;
This might help you out.
Thanks.
Venkat.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Any value entered by user is string. String can hold all (chars, special chars, numbers,..etc..).
For example if you want to validate if there are any numeric chars in the string you can use the below method.
public boolean isNumericCharsExist(String s)
{
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++)
{
if (Character.isDigit(chars<i>))
return true;
}
return false;
}
Regards,
Charan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.