开发者

how to validate alphanumeric numeric and higlight the fields using jquery

开发者 https://www.devze.com 2023-03-11 04:27 出处:网络
I am looking for validation using jquery on a simple form and I want to know how I can check for alphanumeric or numeric.Then I want to highlight the error text field using rules.This code is working

I am looking for validation using jquery on a simple form and I want to know how I can check for alphanumeric or numeric. Then I want to highlight the error text field using rules. This code is working great is entered in the fields can anyone help on a开发者_如何学Cdding this functionality to my code?

here is the code i have used

$("#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>"}


      }
    });


you can add a custom rule to validate the alphanumeric characters. For this create a custom rule and validate using some regular expression in the custom created method. Check the SO post here

0

精彩评论

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