jQuery字母数字验证 [英] jquery alphanumeric validation

查看:107
本文介绍了jQuery字母数字验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$('#reg_submit').click(function () {
  var reg_password1 = $('#reg_password1').val();
  letters = /([a-z])([0-9])/; 
  var errorMessage =  '';

  if ( ! reg_password1.value.match(letters) )   
  {   
    errorMessage = "Password must be alphanumeric";
    $('#msg_regpass1').html(errorMessage).show();
  }
  else {
    $('#msg_regpass1').html('').hide();
  }
});

我使用上面的jquery代码将字母数字验证应用于我的注册页面.但是我遇到了与match()相关的javascript错误,类似的东西未定义. 任何人都可以为上述问题提出解决方案的建议,或者请提供其他一些代码来获取上述代码的字母数字验证. 该字母模式也无法正常用于字母数字验证.有人可以建议其他模式

i used the above jquery code for applying alphanumeric validation to my registration page.but i am getting the javascript error related to match(), something match is undefined like that. can anyone suggest the solution for the above problem or please provide some other code for getting alphanumeric validation for above code. that letters pattern also not working properly for alphanumeric validation.can anyone suggest other pattern

预先感谢

推荐答案

这个对我有用:

var reg_password1 = 'test123#';
var letters = /^[a-zA-Z0-9]+$/;

var result = letters.test(reg_password1);

console.log(result);​

演示

这篇关于jQuery字母数字验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆