This is a code snippet for basic Java Script to validate email address using a regular expression.This is building on my previous post on how to use regular expressions with j Query. Update 12/05/13: Separated into versions for testing.
Jsp code for validating email address online dating after cancer
Anything more complex becomes error-prone or even contain hidden performance killers. The only comprehensive RFC compliant regex based validator I'm aware of is email-rfc2822-validator with its 'refined' regex appropriately named
It supports only the older RFC-2822 spec though, although appropriate enough for modern needs (RFC-5322 it in areas already out of scope for daily use cases).
For example, the following is a legitimate address, according to spec, spaces and all: No mail server would allow that, but this class can parse it (and rewrite it to a usable form). This means 1.4 has not been made final for three years (2008-2011). I'm looking for a better option, but didn't find one that is very adopted.
We found the existing Java email parser options to be insufficiently durable (meaning, all of them could not parse some valid addresses), so we created this class. I want to use something that is well tested, don't want to hit any bugs.
The code as written has a javamail dependency, but it's easy to remove if you don't want the minor functionality it provides. However, its thoroughness (or the Java RE implementation) leads to inefficiency - read the comments about parsing times for long addresses. For example @ is allowed multiple times depending on context, how do you know the required one is there?