开发者

jQuery Validation for Text box

开发者 https://www.devze.com 2022-12-27 06:23 出处:网络
I want to validate the textbox which should accept only \"letters\" and \".\" and \"/\". how to do this using jquery plugin?

I want to validate the textbox which should accept only "letters" and "." and "/".

how to do this using jquery plugin?

thanks in ad开发者_如何学Govance.jquery vlidt


You will need to extend the validation plugin to use a regular expression as discussed in this post here: StackOverflow

    $.validator.addMethod( 
        "regex", 
        function(value, element, regexp) { 
            var check = false; 
            var re = new RegExp(regexp); 
            return this.optional(element) || re.test(value); 
        }, 
        "Please check your input." 
); 

$("Textbox").rules("add", { regex: "^[a-zA-Z./]+" })  - I think this reg expression is right...?

And for your specific example, a list of regular expressions can be found here

0

精彩评论

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