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.
views:
49answers:
1
+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
2010-09-27 10:44:20
I tried your solution.It accepts 2A as valid input.It shouldn't.
gizgok
2010-09-27 12:52:49
@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
2010-09-27 14:17:01
That is quite possible.But it ain't working.This is what is working [^A-Z0-9].
gizgok
2010-09-27 16:33:03
@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
2010-09-27 16:49:35
Event eh changed answer doesn't work.It's accepting 1e1 as valid input which is even more baffling
gizgok
2010-09-29 14:26:10
Did it.Thanks for your help.
gizgok
2010-09-29 15:41:48