Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is my JQuery code to simple email validation:

var booking_email = $('input[name=booking_email]').val();

 if(booking_email == '' || booking_email.indexOf('@') == -1 || booking_email.indexOf('.') == -1) {

   // perform my alert

 }

The above code allows only emails like '@domain.com' or 'user@domain.' as it only checks for a full stop and an @ symbol. Can anyone tell me how can I code this efficiently?

1 Answer

0 votes
by (19.7k points)

Check the below code implementation:

var booking_email = $('input[name=booking_email]').val();

if( /(.+)@(.+){2,}\.(.+){2,}/.test(booking_email) ){

  // valid email

} else {

  // invalid email

}

Interested in Java? Check out this Java Certification by Intellipaat.  

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Mar 15, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
asked Mar 4, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
asked Jan 6, 2021 in AWS by Amyra (12.9k points)

Browse Categories

...