← servoy magazine

[Tip] Validate email addresses

  • Tips

by Harjo Kompagnie
Direct ICT

Use this method to check for the validity of email addresses:

var x = 'harjo@directict.nl'
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (filter.test(x))
{
    var b = 'YES! Correct email address'
}
else
{
    var b = 'NO! Incorrect email address';
}

Comments (3)

Robert J.C. Ivens
Great tip Harjo! And just at the moment I was ready to implement such a check. Thanks!
Henry Buckweet
Hello Harjo, Nice tip but can you please explain what you are doing here? I don't understand this at all... Thank you, Henry
David Workman
He's using a regular expression to validate two things about the email address string: the format and allowed characters. This is standard JavaScript and you can find tons of information on it by googling "email validation with javascript".