1
votes

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
What's acceptable after the P? Do the other portions (Y, M, W, d) have to be provided or are they optional? Your current regex will most certainly accept the input string P because you've used the * quantifier on all of the other portions. - eldarerathis
the acceptable after the P is number such as 0-9. The other portions (Y,M,W,d) is optional, but you need to type in at least one char such as P3Y or P3M. - user1063808

1 Answers

0
votes

Try

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