Date Validation - Help!!

Results 1 to 2 of 2

Thread: Date Validation - Help!!

  1. #1
    Join Date
    Dec 1969

    Default Date Validation - Help!!

    Ive had the following problem for the past day and can&#039;t seem to solve it. I am new to JavaScript, so am not sure how to work around this but I am sure it is something simple. <BR><BR>The following piece of JavaScript code is taken from my ASP page for a date validation. The validation works correctly but I do not want to make the field compulsory. However the error message still appears even if the user has not entered a value. Please could somebody tell me what to code in order to get empty values accepted...?<BR><BR>The code is as follows: <BR><BR><BR>function validDate(formField,fieldLabel,required)<BR>{<BR> var result = true;<BR> <BR> if (result)<BR> {<BR> var elems = formField.value.split("/");<BR> <BR> result = (elems.length == 3);<BR> <BR> if (result)<BR> {<BR> var day = parseInt(elems[0],10);<BR> var month = parseInt(elems[1],10);<BR> var year = parseInt(elems[2],10);<BR> result = allDigits(elems[0]) && (day &#062; 0) && (day &#060; 32) &&<BR> allDigits(elems[1]) && (month &#062; 0) && (month &#060; 13) &&<BR> allDigits(elems[2]) && ((elems[2].length == 2) &#124&#124 (elems[2].length == 4))<BR> }<BR> <BR> if (!result)<BR> {<BR> alert(&#039;Please enter a valid date (dd/mm/yyyy) in the "&#039; + fieldLabel +&#039;" field.&#039;);<BR> formField.focus();<BR> result = false; <BR> }<BR> } <BR> <BR> return result;<BR><BR>}<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Date Validation - Help!!

    Why don&#039;t you just add a check for an empty field at the start of the function...<BR><BR>if (formField.value == &#039;&#039;) return true;

Posting Permissions

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