JavaScript Validation Problem

Discussion in 'JavaScript' started by me_90, Apr 1, 2008.

  1. #1
    Hi,

    i have a form with javascript to make sure the content of the form is valid..

    the script WORKED and did as it was supposed to until a added a new function

    
    function validateForm(form)
    {
      var fe = form.elements;
      //validate horse
        if (!requiredCheck(fe['dbhorsename'], 'Horse Name')) return false;
      //validate dob
        if (!requiredCheck(fe['dbDOB'], 'Date of Birth')) return false;
    -this is the new line-    if (!validDob(fe['dbDOB'], 'Date of Birth')) return false;
      // ueln
        if (!requiredCheck(fe['dbUELN'], 'UELN')) return false;
        if (!validPhone(fe['dbUELN'], 'UELN')) return false;
    
      return true;
    }
    
    Code (markup):
    the new function
    function validDob(fieldObj, fieldName) {
        validDobRegEx = ^([1-9]|0[1-9]|[12][0-9]|3[01])\D([1-9]|0[1-9]|1[012])\D(19[0-9][0-9]|20[0-9][0-9])$
        if (!fieldObj.value.match(validDateRegEx)) {
            alert(fieldName+' is  not a valid date. Please correct and try again.');
            fieldObj.focus();
            return false;
        }
        return true;
    }
    Code (markup):
    if i comment out the function valid Dob and comment out the code to call valid Dob the rest of the code works fine, with no problems. when i uncomment the function none of the validation works, not even the validation that worked previously.

    anyone have any ideas what is causing this? thanks :confused:
     
    me_90, Apr 1, 2008 IP