Login | Register | FAQ
Anonymous

Date Textbox

+ Post a reply

3 posts Page 1 of 1


Date Textbox

by tqmd1 » Mon Dec 19, 2011 7:49 am

Dear Experts

How to validate a textbox to accept only british type date as dd/mm/yyyy

Please help
User avatar

tqmd1

  • Posts: 51
  • Joined: Fri Oct 28, 2011 11:05 am

Re: Date Textbox

by atik » Mon Dec 19, 2011 12:27 pm

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.
User avatar

atik

  • Posts: 472
  • Joined: Mon Oct 17, 2011 4:55 pm

Re: Date Textbox

by mariaantonietta » Mon Dec 19, 2011 12:33 pm

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
User avatar

mariaantonietta

  • Posts: 64
  • Joined: Mon Oct 31, 2011 7:23 pm


+ Post a reply

Page 1 of 1