My application takes userid from user as input, the userid is alphanumeric i.e just the first character is (a-z), other part is numeric. How can I validate input of this type ( like G34555) ?
+3
A:
Use a regex. This should do it assuming the first letter can be upper or lower case:
Pattern p = Pattern.compile("[a-zA-Z][0-9]+");
Matcher m = p.matcher("some text you want");
boolean isAlphaNum = m.matches();
jqpubliq
2010-04-18 17:44:42
it doesn't work, never return true. any suggestions?
rob
2010-04-18 20:36:29
A:
I have resolved issue by using simple string
function matches
String str="mystring";
str.matches("[a-zA-Z][0-9]+");
rob
2010-04-18 23:48:22
A:
http://osdir.com/ml/Android-Developers/2009-11/msg02501.html seems like a more decent solution, it does not allow entering the chars that are not accepted.
Heikko
2010-08-03 10:04:32