Mark Estrada
Mark Estrada

Reputation: 9191

Allow ascii character during jsf regex validation

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.

Upvotes: 0

Views: 1137

Answers (1)

BalusC
BalusC

Reputation: 1108732

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:

Upvotes: 2

Related Questions