cancel
Showing results for 
Search instead for 
Did you mean: 

How can i validate the given data is string or not

Former Member
0 Kudos

Hi All,

How can i validate the given data is string or not

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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.

Answers (1)

Answers (1)

Former Member
0 Kudos

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