Reputation: 391
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
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
Reputation: 2485
this is working for me .
^([a-zA-Z+]+[0-9+]+)|([0-9+]+[a-zA-Z+]+)$
Upvotes: -1
Reputation: 160843
You mean you want at least one number?
You could use look-ahead assertion.
/^(?=.*\d)[a-z\d]*$/i
Upvotes: 5