views:

172

answers:

3

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
it doesn't work, never return true. any suggestions?
rob
A: 

I have resolved issue by using simple string function matches

String str="mystring";

str.matches("[a-zA-Z][0-9]+");

rob
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