3

In reference to this question, it still accepts 8/1/201987 as a date, where in 201987 is not in yyyy format.

How to ensure yyyy format? Do I need to validate it in the bean?

I have used the code below :

<p:calendar ...>
    <f:convertDateTime pattern="dd/MM/yyyy" />
</p:calendar>

But as it uses SimpleDateFormat, if you give yyyy it accepts any number of digits.

How to resolve this issue?

Community
  • 1
  • 1
Nikita
  • 255
  • 1
  • 4
  • 10
  • Avoid the `` mess and simply use the `pattern` attribute associated with ``. Use, if necessary, a custom converter of your own (probably using other than the poorly-implemented `java.util.Date` API). – Tiny Aug 23 '15 at 11:07

2 Answers2

1

Try mask for p:calender like mask="99/99/9999", it's works fine for me

<p:calendar value="8/1/201989" mask="99/99/9999">
    <f:convertDateTime pattern="dd/MM/yyyy" />
</p:calendar>
  • The problem with this masking is that it still considers 55/55/5555 as a valid date. Is there any way by which we can prevent user from entering month greater then 12 and days greater then 31? – v0ld3m0rt Oct 24 '17 at 14:19
0

You can restrict the user input by adding attributes mask="true" and maxlength=10