You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@syncope.apache.org by Riccardo Costa <ri...@intesys.it> on 2013/03/29 11:31:28 UTC

Email address validator

Hi Syncopers,

I'm currently using Syncope 1.0.6 and I've just try to use an "email" attribute of type string with validator class "org.apache.syncope.core.persistence.validation.attrvalue.EmailAddressValidator".
I set email attribute to value "riccardo.costa-dev@intesys.it" but I received "Error:{[InvalidValues [email: riccardo.costa-dev@intesys.it]], }"
I think that current email validator regular expression is a bit restrictive:

private static final Pattern EMAIL_PATTERN = Pattern.compile("^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$", Pattern.CASE_INSENSITIVE);

I'd like to suggest an improvment with something like this [1]

private static final Pattern EMAIL_PATTERN = Pattern.compile("^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$", Pattern.CASE_INSENSITIVE);

WDYT?

Best regards.
Riccardo.

[1] ref: http://www.regular-expressions.info/email.html

Re: Email address validator

Posted by Francesco Chicchiriccò <il...@apache.org>.
On 29/03/2013 11:31, Riccardo Costa wrote:
> Hi Syncopers,
>
> I'm currently using Syncope 1.0.6 and I've just try to use an "email" attribute of type string with validator class "org.apache.syncope.core.persistence.validation.attrvalue.EmailAddressValidator".
> I set email attribute to value "riccardo.costa-dev@intesys.it" but I received "Error:{[InvalidValues [email: riccardo.costa-dev@intesys.it]], }"
> I think that current email validator regular expression is a bit restrictive:
>
> private static final Pattern EMAIL_PATTERN = Pattern.compile("^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$", Pattern.CASE_INSENSITIVE);
>
> I'd like to suggest an improvment with something like this [1]
>
> private static final Pattern EMAIL_PATTERN = Pattern.compile("^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$", Pattern.CASE_INSENSITIVE);
>
> WDYT?

+1, looks good to me (and applies to 1.1.0 as well).

Please file an improvement on JIRA and provide a patch.

In the meanwhile you can of course define your own mail validator class 
and use it in your project.

Regards.

> [1] ref: http://www.regular-expressions.info/email.html

-- 
Francesco Chicchiriccò

ASF Member, Apache Syncope PMC chair, Apache Cocoon PMC Member
http://people.apache.org/~ilgrosso/