primefaces keyfilter regular expression

8.2k Views Asked by At

I got a problem regarding to the keyfilter from primefaces extension. I want to define a regular expression for a time period for example "P1Y3M2W1d". The following regular expression for the key filter is used:

<pe:keyFilter regEx="/P[0-9]*Y*[0-9]*M*[0-9]*W*[0-9]*d*/" />

The goal is that user might only type in P first then digit number 0-9, afterwards Y(year), M(Month) or W(Week) and so on. The problem is I can only type in captial P and nothing else. I check the regular expression. It is correct. What is the problem with regular expression in keyFilter? Thanks for help!!!

Update:

<p:inputText value="#{cc.attrs.value}" id="period" >
   <pe:keyFilter regEx="/P([0-9]+Y)?([0-9]+M)?([0-9]+W)?([0-9]+d)?/" />
</p:inputText>

I think primefaces extension uses the jquery keyfilter plugin. The regEx should be quoted around "//", but somehow the only possibility in my UI is to captial P

1

There are 1 best solutions below

6
On

Try

regEx="/P([0-9]+Y)?([0-9]+M)?([0-9]+W)?([0-9]+d)?/"