2012-10-19 51 views
0
<script type="text/javascript"> 
      /* <![CDATA[ */ 
      jQuery(function(){ 
       jQuery("#ValidNumber").validate({ 
        expression: "if (!isNaN(VAL) && VAL) return true; else return false;", 
        message: "Should be a number" 
       }); 
       jQuery("#Email").validate({ 
        expression: "if (VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;", 
        message: "Should be a valid Email id" 
       }); 
       jQuery("#ValidNumber").validate({ 
        expression: "if (VAL > 100) return true; else return false;", 
        message: "Should be greater than 100" 
       }); 
       jQuery("#Mobile").validate({ 
        expression: "if (VAL.match(/^[9][0-9]{9}$/)) return true; else return false;", 
        message: "Should be a valid Mobile Number" 
       }); 
      }); 
      /* ]]> */ 
     </script> 

其實這是我的jQuery來我的問題我怎麼能重置驗證與文本字段一起當我在表單按復位鍵腳本來重置驗證它涉及什麼程序。jQuery的驗證:我想,當我按下復位按鈕

回答

0

當你綁定您的驗證碼爲一個調用validate這樣的:

window.validator = $('form#your_formid').validate({ 
rules: { 
    validNumber: { 
     expression: "if (!isNaN(VAL) && VAL) return true; else return false;" 
    }, 
    email: { 
     required: true, 
     email: true 
    }, 
    // ... 
}, 
messages: { 
    validNumber: { 
     expression: 'Should be a number' 
    }, 
    email: { 
     required: 'Fill in your email, 
     email: 'Valid email please' 
    } 
} 

您可以撥打resetForm在去驗證對象,當你點擊復位按鈕

window.validator.resetForm();