i am making email validation for an input with regular expression as follows:
<h:inputText id="email" value="#{settingsBean.aFriendEmail}" required="true" label="Email" validatorMessage="#{settingsBean.aFriendEmail} is not valid">
<f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
</h:inputText>
<p:message for="email" />
and i was wondering how to make this validation onblur/on focus lost for that input.
please advise how to accomplish that, thanks.
also, i want to restrict the valid domains to be .com, .net, .org
any advises about that ?
Add a
<f:ajax>which is hooked onblurevent and updates the message on complete.Restricting the email domain by regex is a separate question completely unrelated to JSF.
Unrelated to the concrete problem, your
validatorMessageis not right.The model value is never updated when the validation has failed, so this would always print the initial value, which may be null/empty. You should instead display the component’s submitted value.