0

I have this code to validate an email address and I think it works fine for normal circumstances

<h:inputText id="email" value="#{myBean.email}"
        required="true">
    <f:validateRegex pattern="[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}" />
</h:inputText>

But if somebody enters this sample email

lòmbardi.Çorneliö@mymail.com

..the regex fails.

Question, is there a way to have a validator allows other ascii characters?

Thanks.

Aritz
  • 30,971
  • 16
  • 136
  • 217
Mark Estrada
  • 9,013
  • 37
  • 119
  • 186
  • Have a look at http://stackoverflow.com/questions/5071236/java-regexp-to-match-ascii-characters – Craig May 28 '13 at 03:03
  • You might also want to allow lòmbardi.Çorneliö@[παράδειγμα.δοκιμή](http://παράδειγμα.δοκιμή), lòmbardi.Çorneliö@subdomain.mymail.com, etc. – Tom Blodget May 28 '13 at 04:06
  • ahh yes...that seems logical now.. so I am thinking more on this matter...any thoughts? – Mark Estrada May 28 '13 at 04:09

1 Answers1

2

Just don't validate only latin characters in A-Z range. This makes since May 2010 no sense anymore as practically any unicode character is allowed in domain name. It's much better to validate only the occurrence of the @ and . characters.

<f:validateRegex pattern="([^.@]+)(\.[^.@]+)*@([^.@]+\.)+([^.@]+)" />

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555