I am trying to validate a texbox to allow numbers and letter(s) but not letters alone only e.g. 13492M
I am using C# regular expressions.
I am trying to validate a texbox to allow numbers and letter(s) but not letters alone only e.g. 13492M
I am using C# regular expressions.
^[A-Za-z]*\d[A-Za-z\d]*$ should do it. (Possibly some letters, then a digit, then any more letters or digits.)
(Edited to add start/end matches.)
\d in the first []. Depending on how the regex engine works, that might improve performance.How about this:
([0-9]+[a-zA-Z]+ | [a-zA-Z]+[0-9]+)[a-zA-Z0-9]*
(Numbers first and then alphabets OR Alphabets first then numbers) atleast once or more then both alphabets and numbers which is optional
This Regex should work fine:
^[A-Za-z]*[0-9]+[A-Za-z]*$
This regex will allow numbers or letters+numbers. Just letters will fail.
A1B2. But who knows what the OP wants.Simply,
Pattern = "^[a-zA-Z0-9]*[0-9]+[a-zA-Z0-9]*$"
Details :
^[a-zA-Z0-9]*[0-9]+[a-zA-Z0-9]*$^[a-zA-Z0-9]+$|^[0-9]+$ part is completely useless now. And your code looks like it might suffer from performance issues, at least it's non trivial to optimize this for a regex engine. Compare it with Rawling's code.