max
max

Reputation: 391

Regular Expression either numeric characters or both alpha-numeric but not only alpha characters

To validate a field that must have both numbers and letters, I could use:

/^([0-9]+[a-zA-Z]+|[a-zA-Z]+[0-9]+)[0-9a-zA-Z]*$/

But I want to additionally accept numeric only strings.

Upvotes: 3

Views: 8571

Answers (3)

max
max

Reputation: 391

i got the answer from http://www.javascripter.net/faq/regularexpressionsyntax.htm

well i can do an "or" function inside regx

/^([0-9]|([0-9]+[a-zA-Z]+|[a-zA-Z]+[0-9]+)[0-9a-zA-Z]*)$/;

Upvotes: 3

Lalit kumar
Lalit kumar

Reputation: 2485

this is working for me .

^([a-zA-Z+]+[0-9+]+)|([0-9+]+[a-zA-Z+]+)$

Upvotes: -1

xdazz
xdazz

Reputation: 160843

You mean you want at least one number?

You could use look-ahead assertion.

/^(?=.*\d)[a-z\d]*$/i

Upvotes: 5

Related Questions