Is there a way to check if a character is alphanumeric. I was trying the code below but am picking up "all" characters. The
string of data that I am checking should only have an alphanumeric in a particular position. I have the position part down pat but not the check. Did I need to "create" an alphanumeric table to compare. Thanks
/**
* Returns True if given String contains only numeric characters,
* otherwise returns False
*/
private boolean isNumeric(String newString)
{
char[] chars = newString.toCharArray();
Character c;
for (int x = 0; x < chars.length; x++)
{
if (!Character.isDigit(chars[x]))
{
return false;
}
}
return true;
}
/**
* Returns True if given String contains an alphanumeric,
* otherwise returns False
*/
public boolean isLetterOrDigit(String newString)
{
if ((newString == null) | | (newString.length()==0))
return false;
char[] chars = newString.toCharArray();
for (int x = 0; x < chars.length; x++)
{
if (!Character.isLetterOrDigit (chars [x]))
{
return false;
}
}
return true;
}//end method