How to block gmail address entry in a text box or show a popup?

I need textboxin my form to enter an email address. But the address must be a business email. No one allows you to enter a personal gmailor yahooaddress or show a pop-up warning at the same time. How to implement this? Can I use angulars ng-patternto implement it?

+4
source share
1 answer

You can do something like this. No angular template needed.

HTML

<form id="signup" method="post">
    <input id="email" type="email" placeholder="Your e-mail." />
</form>

Js

$('#email').blur(function() {
    validateEmail($('input').val());
    return false;
});

function validateEmail(email) {
    var re = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
    if (re.test(email)) {
        if (email.indexOf('@yourdomain.com', email.length - '@yourdomain.com'.length) !== -1) {
            alert('Valid email.');
        } else {
            alert('Email must be a yourdomain e-mail address (your.name@yourdomain.com).');
        }
    } else {
        alert('Not a valid e-mail address.');
    }
}

Tick fiddle

Link

+1
source

All Articles