I would need to validate my date. But when I key in 01132014 , it doesn't show any error message and it prints out 01 Jan, 2015 Also when I key in 06035555, it doesn't print out any error and continue to show 06 Mar 5555
But if I key in weird dates like 33333333, it does prints out "Your input has no logic at all"
Additionally, I do not want the error message to pop up an alert box. I want the error message to be shown on the textbox itself. How do I do it?
May I know what should I add in to validate? I tried to view other answers but still, it's not working.
Javascript:
function parseDate(s) {
if (isNaN(Date.parse(s))) {
alert("Your input has no logic at all");
return;
}
var reg = /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/g;
var dateParts = s.split("/");
var date = new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]);
var dateStrParts = date.toString().split(" ");
return (date.getDate() + ", " + dateStrParts[1] + " " + dateStrParts[3]);
}
</script>
Calendar Tag:
<p:calendar
value="#{pc_Rpt2202.asat_date}"
id="rp2202_input_as_at"
styleClass="calendar"
maxlength="10"
pattern="dd MMM yyyy"
onchange="$(this).val(parseDate($(this).val()))"
onfocus="$(this).mask('99/99/9999');"
>
<p:watermark for="rp2202_input_as_at" value="dd/MMM/yyyy" />
<f:convertDateTime pattern="dd MMM yyyy" />
</p:calendar>