I'm making a really simple email validation script that basically just checks the following
- that the email isn't blank
- the the email contains an @ symbol with at least 1 character before it
- that there is a domain ie @ with at least 2 letters after it
- that it ends with a fullstop with at least 2 letters after it
I know there are many more checks, but I look at these regex rules and my mind stops working. I figure if I started with something small like this I might be able to wrap my brain around more complex rules.
Currently using some jquery I do the following:
var booking_email = $('input[name=booking_email]').val();
if(booking_email == '' || booking_email.indexOf('@') == -1 || booking_email.indexOf('.') == -1) {
// perform my alert
}
This is enough to stop 90% of bogus emails so far... I would just like to make it a bit more effective because currently my rule will allow emails like '@domain.com' or 'user@domain.' because it only checks that there is a fullstop and an @ symbol.
Thanks for any tips.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…