开发者

Jquery check for alphanumeric charactres

开发者 https://www.devze.com 2023-03-11 05:50 出处:网络
In the below codeUsing jquery how to check for only alaphanumeric charaters.Even space and none of the special symbols should be allowed.I do want o use a external plugin

In the below code Using jquery how to check for only alaphanumeric charaters.Even space and none of the special symbols should be allowed.I do want o use a external plugin

 var a='a hjdshj%^& ff234 ./.';

  if(var a has special ch开发者_运维问答aracters)
  {
      alert('has special characters');
  } 

EDIT : Even single and double quotes should not be allowed


There is no need of any plugin to check this

you can make use of Regular exprssion to do it easily..

try this

var str='a hjdshj%^& ff234 ./.';
var re = new RegExp(/\$|\/|\^|-/\s,"g");
specialchars = str.match(re);
alert(specialchars.length);
0

精彩评论

暂无评论...
验证码 换一张
取 消