0

Not sure why my alerts aren't firing, but what I eventually would like to do is enable the submit button when this field is not empty and contains a specific email address, such as "@something.com"

First things first, I'm simply trying to check if the field is empty on the change event.

HTML

<input type="email" id="email" placeholder="lauren@something.com">

JS

$("#email").change(function(){
    if (this.is(':empty')) {
        alert('empty');
    } else {
        alert('not empty');
    }
});

1 Answers1

0
$("#email").change(function(){
    var domain = this.value.indexOf('@') != -1? this.value.split('@').pop() : '';

    if (this.value.trim() == '') {
        alert('empty');
    }else if (this.value.trim() == 'bill@gates.com') {
        alert('Holy crap, it\'s Bill Gates');
    }else if (domain == 'gates.com') {
        alert('It\'s a radiator hose salesman ?');
    }else{
        alert('someone else');
    }
});
adeneo
  • 312,895
  • 29
  • 395
  • 388