Reputation: 379
Hi all i need a regex
that accepts first letter as character and the remaining should be digits.
Even spacing is not allowed too..
Possible cases : a123, abc123, xyz123 and so on ...
Unacceptable : 123abc,1abc12, a 123 and so on..
i tried some think like this but i am not sure this works so can any one help me..
"[A-Z][a-z]\d{0,9}"
Upvotes: 0
Views: 276
Reputation: 593
I would highly recommend you do not limit yourself to ASCII as most of the other answers for this question do.
Using character classes, which I recommend, you should use:
^[\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Pc}]\d+$
See the reference for ^
and $
.
Upvotes: 0
Reputation: 267
[A-Z]|[a-z]{1,}\d{1,}
But as you mentioned, possible cases should be: a123, b321, z4213213, but not abc123. Right?
So regExp shoud be [A-Z]|[a-z]\d{1,}
.
Upvotes: 0
Reputation: 336128
^[A-Za-z]+[0-9]+$
matches one or more ASCII letters, followed by one or more ASCII digits. If digits are optional, use [0-9]*
instead.
If you want to also allow other letters/digits than just ASCII, use
^\p{L}+\p{D}+$
Upvotes: 2