Validating a date

Results 1 to 2 of 2

Thread: Validating a date

  1. #1
    Join Date
    Dec 1969

    Default Validating a date

    I&#039;m sure I am missing something simple here but I can&#039;t seem to think of it. What I am needing is to run a js function when a field is changed to see if the text entered is in a valid date format. Any help is appreciated.<BR><BR>&#060;input type="text" id="reviewdate" name="formreviewdate" size=15 style="font-size: 8pt" onChange="checkDate()"&#062;<BR><BR><BR>function checkDate(){<BR>var rev = new Date(document.UpdateCCR.reviewdate);<BR> if(rev.value == false) {<BR> alert("Check the date");<BR> document.UpdateCCR.reviewdate.focus();<BR> return (false);<BR> }<BR>return (true);<BR>}

  2. #2
    Join Date
    Dec 1969

    Default In the left panel of this page...

    Find "JScript Reference" and click on it.<BR><BR>In the list of topics that appears, find "Objects" and click on it.<BR><BR>In the list of objects that appears, find "Date Object" and click on it.<BR><BR>In the lists of properties and of methods near the bottom of that page, see if you can find one named "value". If so, click on it.<BR><BR>Hmmm...No "value" property, is there?<BR><BR>So can you guess why <BR> rev.value<BR>would give you an error?<BR><BR>Of course, even before that you goofed, omitting the ".value" property here:<BR> var rev = new Date(document.UpdateCCR.reviewdate[hl="yellow"].value[/hl]);<BR><BR>Might I suggest that you visit and look in their JavaScript FAQ and see if they don&#039;t have code that shows how to validate dates?<BR><BR>

Posting Permissions

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