Jquery Removeclass and Form Validation -


i have here form validation. textbox doesn't allow special character except (-) using jquery validation. problems validation in bid , rfq textbox isn't working. accepts special characters , submit form.

this working fiddle. http://jsfiddle.net/mhck7/1/

help please?

jquery(function($) {     var validation_holder;      $("form#register_form input[name='submit']").click(function() {      var validation_holder = 0; //  /^[a-za-z\s]+$/           var rfq         = $("form#register_form input[name='n_rfq']").val();         var rfq_regex   = /^[0-9\-]+$/; // reg ex qty check         var bid             = $("form#register_form input[name='n_bid']").val();         var bid_regex   = /^[0-9\-]+$/; // reg ex qty check         var mode                = $("form#register_form select[name='n_mode']").val();         var mode_regex      =  /^[a-za-z ]+$/; // reg ex qty check          /* validation start */    if(bid == "" || bid.hasclass("mandatory")) {         $("span.val_bid").html("this field required.").addclass('validate');         validation_holder = 1;     } else {         if(!bid_regex.test(bid)){ // if invalid phone             $("span.val_bid").html("integer allowed!").addclass('validate');             validation_holder = 1;          } else {             $("span.val_bid").html("");         }     }      if(rfq == "" || rfq.hasclass("mandatory")) {         $("span.val_rfq").html("this field required.").addclass('validate');         validation_holder = 1;     } else {         if(!rfq_regex.test(rfq)){ // if invalid phone             $("span.val_rfq").html("integer allowed!").addclass('validate');             validation_holder = 1;          } else {             $("span.val_rfq").html("");         }     }          if(mode == "") {             $("span.val_mode").html("this field required.").addclass('validate');             validation_holder = 1;         } else {             if(!mode_regex.test(mode)){ // if invalid phone                 $("span.val_mode").html("invalid special characters!").addclass('validate');                 validation_holder = 1;              } else {                 $("span.val_mode").html("");             }         }                     if(validation_holder == 1) { // if have field blank, return false             $("p.validate_msg").slidedown("fast");             return false;         }  validation_holder = 0; // else return true         /* validation end */         }); // click end   }); // jquery end    $('#txt1').change(function () { if ($(this).val() == 'negotiated' || $(this).val() == 'shopping' || $(this).val() == '') {     $("#txt2,#txt3").val('');     $("#txt2").removeclass("mandatory");     $("#txt3").removeclass("mandatory"); } else if ($(this).val() == 'bidding') {     $("#txt3").val('');     $("#txt3").removeclass("mandatory"); } else if ($(this).val() == 'rfq') {     $("#txt2").val('');     $("#txt2").removeclass("mandatory"); } else {     //here can specify if value not negotiated or shopping } }); 

actually believe problem errors on

if(bid == "" || bid.hasclass("mandatory")) { 

any attempt return false after point ignored... because bid val not html element!


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -