jQuery validate plugin : accept letters only?

后端 未结 8 1374
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 07:23

I\'m using the validate plugin from http://bassistance.de/jquery-plugins/jquery-plugin-validation/

What i\'m trying to find is a way to make some of my form fields a

相关标签:
8条回答
  • 2020-11-29 08:13

    Add cdn

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.0/additional-methods.js"></script>
    rules:{
        txtname:{required: true,
                lettersonly:true
                }
    
    0 讨论(0)
  • 2020-11-29 08:15

    Use below code in your script. this will add a new clause to your validator.

    $.validator.addMethod(
            "alphabetsOnly",
            function(value, element, regexp) {
                var re = new RegExp(regexp);
                return this.optional(element) || re.test(value);
            },
            "Please check your input values again!!!."
    );
    $("#formElement").rules("add", {alphabetsOnly: "^[a-zA-Z'.\\s]$" })
    
    0 讨论(0)
提交回复
热议问题