tags:

views:

49

answers:

1

I have a problem where I need to see if the textbox entry is an alphanumeric value. The format for this entry Character(A-Z) then Number(0-9), where there's only one alphabet and Numbers can be as many as he wants.The lphabet should always come first.A minimum of 2 characters have to be entered. Example is A100, A1. It should not accept 1A.

+1  A: 
^[A-Z][0-9]+$

The above means, starting at the beginning of the string, one character in the set A_Z, followed by one or more characters in the set 0-9, followed by the end of the string.

Bryan Oakley
I tried your solution.It accepts 2A as valid input.It shouldn't.
gizgok
@gizgok: I think you are mistaken. The above absolutely won't match 2A. The pattern very specifically is looking for a letter followed by one or more digits. You must be calling your regular expression function wrong, or interpreting the results wrong.
Bryan Oakley
That is quite possible.But it ain't working.This is what is working [^A-Z0-9].
gizgok
@gizgok: the pattern you chose says that the first character must be A-Z or 0-9. It will match all sorts of things that aren't what you originally asked for. You are on the right path thinking about using ^. I've modified my answer to include anchors, since you want to match against a whole string. Try it and see if it works for you.
Bryan Oakley
Event eh changed answer doesn't work.It's accepting 1e1 as valid input which is even more baffling
gizgok
Did it.Thanks for your help.
gizgok