p:keyFilter
versus f:validateRegex
– regEx
versus inputRegEx
p:keyFilter
with the regEx
attribute 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 the inputRegEx
attribute or f:validateRegex
.
So, in your case you could use:
<p:inputXxx ...>
<f:validateRegex pattern="([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]"/>
</p:inputXxx>
or:
<p:inputXxx ...>
<p:keyFilter inputRegEx="/([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]/"/>
</p:inputXxx>
Please note that p:keyFilter
requires JavaScript regular expressions, while, while f:validateRegex
requires a Java regular expression. And, p:keyFilter inputRegEx
is checked on key up, while f:validateRegex
is executed when the field is processed. So, in resume:
Property |
p:keyFilter inputRegEx="..." |
f:validateRegex pattern="..." |
Regular expression type |
JavaScript |
Java |
Executed when |
Key up JavaScript event is triggered |
Component is processed |
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…