Validating a Date on Client Side using JScript

Results 1 to 3 of 3

Thread: Validating a Date on Client Side using JScript

  1. #1
    Chris Corraliza Guest

    Default Validating a Date on Client Side using JScript

    I have a textbox that should contain a date. Would like to validate that it is a date on the client side using JScript. I know in VBScript there is the isdate function. What can I do in JScript to make sure it is a true date entered into the textbox? <BR>

  2. #2
    Sam Otto Guest

    Default RE: Validating a Date on Client Side using JScript

    Here is my checkDate function. It uses a regular expression which is available in javascript 1.2 which I think means you must have a 4.X version of a browser...<BR><BR>//-------------------------------------------<BR>// Validate a input (text) field that holds a date.<BR>// blank should be true if empty field is OK.<BR>//-------------------------------------------<BR>function checkDate(field,blank)<BR>{<BR> str = field.value;<BR> if (str=="") return blank;<BR> re = new RegExp("([0-9]{1,2})[ -/]([0-9]{1,2})[ -/]([0-9]{1,4})");<BR> if (str.search(re)==0)<BR> {<BR> m = RegExp.$1;<BR> if (m&#060;13)<BR> {<BR> max = 31;<BR> if (m==2)<BR> {<BR> y = RegExp.$3;<BR> if (y&#060;100)<BR> {<BR> if (y&#060;20)<BR> y = 20 + y;<BR> else<BR> y = 19 + y;<BR> }<BR> if ((y%4==0) && (y%400==0))<BR> max=29;<BR> else<BR> max=28;<BR> }<BR> else if (m==4&#124&#124m==6&#124&#124m==9&#124&#124m==11)< BR> {<BR> max = 30;<BR> }<BR> d = RegExp.$2;<BR> if (d&#060;=max)<BR> return true;<BR> }<BR> }<BR> return false;<BR>}<BR>

  3. #3
    Chris Corraliza Guest

    Default RE: Validating a Date on Client Side using JScript

    Thanks will try it out today. Was thinking about doing something similar.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •