如何验证字母数字数字并使用jquery突出显示字段

时间:2011-06-07 12:25:20

标签: jquery validation jquery-validate

我在简单的表单上使用jquery寻找验证,我想知道如何检查字母数字或数字。然后我想使用规则突出显示错误文本字段。这个代码工作得很好,在字段中输入了,任何人都可以帮助我将这个功能添加到我的代码中吗?

这是我用过的代码

$("#frmstudent").validate({
      rules:{
          txt_name :{ required:true, minlength : 3 },  

          txt_fname:{ required:true, minlength : 3  },

          txt_class:{ required:true, minlength: 2 },

          txt_city:{ required:true, minlength : 3},

          txt_contact:{ required:true, minlength : 5 },

          txt_email:{ required:true, email:true, minlength : 8},

          txt_address:{ required:true , minlength : 10}

      },
      messages:{

          txt_name:{required:"<i>Please enter ur full name</i>",
                    minlength:"<i>please enter at least 3 characters</i>"},

          txt_fname:{required:"<i>Please enter the fathers name in required field</i>",
                    minlength:"<i>please enter at least 3 characters</i>"},

          txt_class:{required:"<i>Please enter the your class name</i>",
                    minlength:"<i>please enter at least 2 characters</i>"},

          txt_city:{required:"<i>Please enter your city name</i>",
                    minlength:"<i>please enter at least 3 characters</i>"},

          txt_contact:{required:"<i>Please enter your contact details</i>",
                    minlength:"<i>please enter at least 5 characters</i>"},

          txt_email:{required:"<i>Please enter your valid email address</i>",
                    minlength:"<i>please enter at least 8 characters</i>"},

          txt_address:{required:"<i>Please enter your address</i>",
                    minlength:"<i>please enter at least 10 characters</i>"}


      }
    });

1 个答案:

答案 0 :(得分:1)

您可以添加自定义规则来验证字母数字字符。为此,创建自定义规则并使用自定义创建方法中的某些正则表达式进行验证。检查SO帖子here