how to find String contain any alphabetic or numeric characters using java? [duplicate]
Possible Duplicate:
Simple way to determine if string is only characters, or to check if string contains any numbers in Java
I want to find if a given String has any alphabetic or numeric characters. How would I do this using java?
Thanks
String s = "%$a*";
Pattern p = Pattern.compile("[a-zA-Z0-9]");
Matcher m = p.matcher(s);
if (m.find())
System.out.println("The string \"" + s + "\" contains alphanumerical characters.");
Take a look at this: http://www.regular-expressions.info/java.html
There are two convenience methods in the Character
class that would help you
isLetter(...)
isDigit(...)
All that's required is transforming a String
to a character array, and then stepping through the array.
精彩评论