Regex alphanumeric jquery

var regx = /^[A-Za-z0-9 _.-]+$/; if(regx.test($($input).val())) alert ("correct"); else alert('Incorrect!'); } 

If I enter the entrance, does the @ or # character work? it works for me, but I think it should be wrong ...

Why doesn't it work fine?

+4
source share
2 answers

You are missing the opening bracket {

Change your if ... else to:

 var regx = /^[A-Za-z0-9 _.-]+$/; if (regx.test('#sdfgsdfg')) alert("correct"); // alerts else alert('Incorrect!');​ 

http://jsfiddle.net/Bp6fg/

+9
source

regex 5-10 alphanumeric jquery var regx = / ^ ([a-zA-Z0-9 _.-]) {3,10} $ /

  $('#txtSearchIn').keyup(function() { if (regx.test(this.value)) $('#lblErrorMsg').val(''); else $('#lblErrorMsg').val('text should be alphanumeric as well as max length 5-10 charater'); }); 
0
source

Source: https://habr.com/ru/post/1397061/


All Articles