javascript/JS限制用户名只能输入字母和数字下划线

var name = $("#uname").val();//待验证的字符串正则表达式

 

if (name.match(/\W/)) {ide

//match函数表示符合,是左边的包含右边(或者说左边出现过右边的);\W(大写W)是指除数字字母下划线之外的元素。若是函数

//是小写,则表明数字字母下划线。;//是js的正则表达式定界符,match函数中正则表达式只需定界符,不须要双引号 。ip

     $("#name-tip-error").hide();字符串

$("#name-tip-success").hide();error

     $("#name-tip-illegal").show();co

     return false;字符

  }数字