2010-12-13 71 views

回答

4
$('#elm').validate(
     { 
      valid: function(inputValue){ 
        return !inputValue.match(/['"]+/); 
      } 
}); 
+0

我不知道如何使用它。請解釋一下。 – 2010-12-13 04:49:21

+2

如果*有*有引號,它們不會匹配嗎? – alex 2010-12-13 04:50:59

+0

引用這個插件:http://plugins.jquery.com/project/jqueryvalidate – 2010-12-13 04:51:49

0

使用正則表達式像^ [A-ZA-Z] 這將接受A-Z和A-Z中的字符。

這裏是代碼: 添加正則表達式的方法。

  $.validator.addMethod("regex",function(value,element,regexp){ 
       var re= new RegExp(regexp); 
       return this.optional(element) || re.test(value); 
      },"Only Characters from A-z"); 

然後你需要在該字段上添加一條規則。

  rules:{ 
        username:{ 
         required:true, 
         regex:"^[a-zA-Z]+$" //Only Characters 
        } 
       }, 
      messages:{ 
         username:{ 
          required:"Mandatory" 
         } 
       }, 

完蛋了..

相關問題