简体   繁体   English

使用jquery.bassistance验证数字

[英]Validation on numbers with jquery.bassistance validation

I used the jquery.bassistance validation plugin. 我使用了jquery.bassistance验证插件。 For validation on my fields. 用于验证我的字段。 Now i want validation on my arrival text box. 现在,我想在到达文本框中进行验证。 I want that he validate on this box. 我希望他在此框上进行验证。 The only characters that you used in this checkbox are numbers and the :. 您在此复选框中使用的唯一字符是数字和:。

How can i make that. 我该怎么做。 I used now this code: 我现在使用此代码:

$(".validate").validate({
        rules: {
            email: {
                required: true,
                email: true
            },
            number: {
                required:true,
                minlength:3,
                phoneAus:true   
            },
            math: {
                equal: 11
            },
            agree: "required"
        },
        messages: {
            email: "Vul een geldig email adres in",
            agree: "Je moet nog akkoord gaan met voorwaarden"
        },
        errorLabelContainer: $("form .error-messages")
    });

But the number validation. 但是数量验证。 Validate on numbers. 验证数字。 How can i fix that the number validation. 我该如何解决数字验证问题。 Accept the : sign. 接受:标志。

Thanks 谢谢

Try adding a custom regex rule, here is a starting point, you will need to update the regex to your specific requirements: 尝试添加自定义正则表达式规则,这是一个起点,您需要将正则表达式更新为您的特定要求:

$(function ()
{
    $.validator.addMethod("customRegex", function(value, element) {
        return this.optional(element) || /^[0-9\:]+$/i.test(value);
    }, "must contain only numbers, or a colon.");

    $(".validate").validate({
        rules: {
            "fieldId": {
                required: true,
                customRegex: true,
            }
        },
        messages: {
            "fieldId": {
                required: "You must enter a xyz",
                customRegex: "format not valid"
            }
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM