Please help with regular expression (string must be letter plus 5 numbers)

P

paulsmith5

Hi,

I'm developing a web app and I want to validate a users input on a
form. I need a regular expression to validate a string which must begin
with a letter (i.e. A-Z or a-z) and must have 5 numbers (0-9) after it.
For example, A12345. Hope someone can help.

Thanks,

Paul
 
G

Guest

Off the top of my head:
^[A-Z]|[a-z][0-9]{9}$

~ Steve

Slight corrections:

^[A-Za-z]\d{5}$

I think that you would have to use a parenthesis to use the | operator, so
put A-Z and a-z in the same characters set.
\d is the same as [0-9]. (Not a currection but more a matter of taste.)
It was supposed to be five digits, not nine.

/Guffa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top