Thursday, 19 September 2013

How do I check if an email field is 1) empty and 2) contains a specific email address with jquery?

How do I check if an email field is 1) empty and 2) contains a specific
email address with jquery?

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

No comments:

Post a Comment