0

Don't allow users to sign up with free email addresses.It must be only with jQuery Validate Plugin

$("form").validate({
        rules: {
            username: {
                required: true,
                minlength: 2,
                nofreeemail: true
            }
        },
        messages: {
            username: {
                required: "Please enter a username",
                minlength: "Your email must consist of at least 2 characters",
                nofreeemail: "Please use your business email"
            }
        }
    });
Tcс
  • 21
  • 1
  • 8
  • 1
    And what exactly is your problem and what have you done so far to solve it? – Björn Tantau Sep 01 '17 at 13:16
  • The [docs](https://jqueryvalidation.org/validate/) show that you can add a `depends` option. Then there you can define an array of keywords not allowed in the email field (gmail, yahoo, etc.) – Laazo Sep 01 '17 at 13:18

1 Answers1

2

Just add new method:

$.validator.addMethod('noemail', function (value) {
    return /^([\w-.]+@(?!gmail\.com)(?!yahoo\.com)(?!hotmail\.com)(?!mail\.ru)(?!yandex\.ru)(?!mail\.com)([\w-]+.)+[\w-]{2,4})?$/.test(value);
}, 'Free email addresses are not allowed.');

rules: {
        username: {
            required: true,
            minlength: 2,
            noemail: true
        }
    },
Alex Home
  • 38
  • 5