Date Textbox
Page 1 of 1
Date Textbox
Dear ExpertsHow to validate a textbox to accept only british type date as dd/mm/yyyy
Please help
Re: Date Textbox
Hi tqmd1,You can do this by using three input. First one can get only two digits and the number will not more then 31, then for second input just like before but here is the limit of 12 and the third on get four digits. If you want to get them as a whole you can do this easily by javascript. If you yet get problems, let us know.
Re: Date Textbox
Hi, perhaps you could use regular expressions to do this. I'm not a regular expression expert, but I've done some research and found this one, which I think works pretty well:/^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[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))))$/
You can use it in a function, for example, along the following lines:
- Code: Select all
function validateDate (dateString)
var regExpr = /^(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((1[6-9]|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((1[6-9]|[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))))$/;
if (regExpr.test(dateString))
{
alert("date format is valid");
}
else
{
alert("date format not valid ");
}
}
the JavaScript method RegularExpression.test(string) checks that a string matches a regular expression and returns true if it does.
I hope it works for you.
tqmd1 wrote:Dear Experts
How to validate a textbox to accept only british type date as dd/mm/yyyy
Please help
Page 1 of 1