1

我正在使用 BootstrapValidator 来验证我的电子邮件输入框。它工作得很好,但是我想阻止某个电子邮件域“@test.com”被验证,我该怎么做?

这是代码:

email: {
                message: 'Your email must be in the format "example@domain.com"',
                validators: {
                    notEmpty: {
                        message: 'Your email is required and cannot be empty'
                    },
                    emailAddress: {
                        message: 'The value is not a valid email address'
                    }



                }
            },
4

1 回答 1

1

您可以使用正则表达式来排除 test.com 域:

email: {
            validators: {
                notEmpty: {
                    message: 'The email address is required and cannot be empty'
                },
                emailAddress: {
                    message: 'The email address is not a valid'
                },
                regexp: {
                    regexp: /^((?!@test\.com).)*$/,
                    message: 'The test.com domain is invalid'
                },
            }
        }

我已经修改了这个小提琴中的引导验证示例,所以你可以看到它工作:http: //jsfiddle.net/pLt295eh/

于 2014-09-19T18:04:03.707 回答