Super simple email validation with javascript
The least possible greedy validation you an do is with this RegExp /^\S+@\S+\.\S+$/
It will only ensure that the address fits within the most basic requirements you mentioned: a character before the @ and something before and after the dot in the domain part (\S
means "anything but a space"). Validating more than that will probably be wrong (you always have the chance of blacklisting a valid email).
Use it like this:
function maybeValidEmail (email) { return /^\S+@\S+\.\S+$/.test(email); }
What others have suggested should work fine, but if you want to keep things simple, try this:
var booking_email = $('input[name=booking_email]').val();
if( /(.+)@(.+){2,}\.(.+){2,}/.test(booking_email) ){
// valid email
} else {
// invalid email
}
Even if you decide to go with something more robust, it should help you understand how simple regex can be at times. :)