Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex alphanumeric jquery

Tags:

jquery

regex

var regx = /^[A-Za-z0-9 _.-]+$/;

if(regx.test($($input).val()))
  alert ("correct");
else
  alert('Incorrect!');
}

If I enter in input, character @ or # works? for me this works, but I think that must be incorrect...

Why does not works fine?

like image 955
hyperrjas Avatar asked Jan 17 '23 11:01

hyperrjas


1 Answers

You're missing an opening brace {

Change your if ... else statement to:

var regx = /^[A-Za-z0-9 _.-]+$/;

if (regx.test('#sdfgsdfg'))
    alert("correct"); // alerts
else
    alert('Incorrect!');​

http://jsfiddle.net/Bp6fg/

like image 96
Alex Avatar answered Jan 25 '23 18:01

Alex