I have an p:inputMask
with a p:keyFilter
to match HH:MM
as following:
p:keyFilter
versus f:validateRegex
p:keyFilter
is used to filter characters (on each key stroke), it does not allow you to validate an expression (on the complete inputted value). If you want to validate if your input matches a regular expression use f:validateRegex
.
So, in your case:
<p:inputMask id="heureDebutPlanningSalleAppareil"
value="#{beanFormPlanningSalleAppareil.planningSalleAppareil.heureDebut}"
required="true" maxlength="4" mask="99:99"
requiredMessage="Heure de début : vous devez indiquer une valeur.">
<f:validateRegex pattern="([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]"/>
</p:inputMask>
You could ajaxify it to show a message on change:
<p:inputMask id="heureDebutPlanningSalleAppareil"
value="#{beanFormPlanningSalleAppareil.planningSalleAppareil.heureDebut}"
required="true" maxlength="4" mask="99:99"
requiredMessage="Heure de début : vous devez indiquer une valeur."
validatorMessage="Your message">
<f:validateRegex pattern="^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$"/>
<p:ajax process="@this" update="heureDebutPlanningSalleAppareilMsg"/>
</p:inputMask>
<p:message for="heureDebutPlanningSalleAppareil"
id="heureDebutPlanningSalleAppareilMsg"/>
You could have a look at pe:timePicker. This component is made for what you are trying to "hack" here.