1

I'm using BootstrapValidator to validate my email input box. It works perfectly, however I want to pervent a certain email domain "@test.com" from being validated, how do I do that?

here is the code:

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'
                    }



                }
            },

1 Answers1

1

You can use a regular expression to exclude the test.com domain:

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'
                },
            }
        }

I've modified the bootstrap validation example in this fiddle so you can see it working: http://jsfiddle.net/pLt295eh/

ChaoticNadirs
  • 2,280
  • 2
  • 20
  • 27