Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  50] [ 1]  / answers: 1 / hits: 80584  / 11 Years ago, tue, april 30, 2013, 12:00:00

I want to check if a string is STRICTLY ALPHANUMERIC in javascript.
i have tried this:



var Exp = /^[0-9a-z]+$/;
if(!pwd.match(Exp))
alert(ERROR)


But the problem with this is it passes input sting if it contains all alphabet or all numeric, i want the function to pass if it contains both Characters and Numbers.


More From » regex

 Answers
5

Try this regex:



/((^[0-9]+[a-z]+)|(^[a-z]+[0-9]+))+[0-9a-z]+$/i


Which allows only Alphanumeric.



It doesn't allow:




  • Only Alpha

  • Only Numbers



Refer LIVE DEMO



Updated:



Below regex allows:



/^([0-9]|[a-z])+([0-9a-z]+)$/i



  • AlphaNumeric

  • Only Alpha

  • Only Numbers


[#78510] Monday, April 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eddiejoshb

Total Points: 659
Total Questions: 105
Total Answers: 100

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
;