Triggering client-side validations based on events
The client-side validations get triggered when the form is submitted, that is when you click on the command component with the validateClient
attribute set to true
. But sometimes, we may want to show validation errors immediately instead of waiting for the user to submit the form.
We can enable instant validations using <p:clientValidator/>
for various events such as change
(default), blur
, keyup
, and so on, as follows:
<p:inputText id="emailId" value="#{userController.registerUser.emailId}" label="EmailId"
required="true" validatorMessage="#{msg['invalid.email']}">
<f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
<p:clientValidator />
</p:inputText>
<p:password id="password" value="#{userController.registerUser.password}"
required="...