Zaloguj | Zarejestruj | FAQ
Anonymous

Date Textbox

+ Odpowiedz

Posty: 3 Strona 1 z 1


Date Textbox

przez tqmd1 » Pn gru 19, 2011 7:49 am

Dear Experts

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

Please help
Avatar użytkownika

tqmd1

  • Posty: 51
  • Dołączył(a): Pt paź 28, 2011 11:05 am

Re: Date Textbox

przez atik » Pn gru 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.
Avatar użytkownika

atik

  • Posty: 471
  • Dołączył(a): Pn paź 17, 2011 4:55 pm

Re: Date Textbox

przez mariaantonietta » Pn gru 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:

Kod: Zaznacz cały
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 napisał(a):Dear Experts

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

Please help
Avatar użytkownika

mariaantonietta

  • Posty: 64
  • Dołączył(a): Pn paź 31, 2011 7:23 pm


+ Odpowiedz

Strona 1 z 1