Validation of a DateField

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Validation of a DateField

chrisch
I'm trying to validate a DateField with a custom validation function that checks if the value of the field is parsed correctly into a Date Object and is not null. Here is my validation function:

var dateValidator = function(value) {
 return (value != null);
}

That works fine so far. The problem is now that the field is not required, the user is allowed to leave it empty. But in this case the value is also null and I cannot determine if the field was intentionally left blank or if the parsing to a date object has failed, because the user has entered a bad string into the date field.

Is there a way to validate it only if the user has entered something?
Reply | Threaded
Open this post in threaded view
|

Re: Validation of a DateField

slah
Hello,

var dateValidator = function(value) {

   var isValidDate = function(value){
      //if check if value is a valide date return true;
      else return false;
   }

   return (value == null || isValidDate (value));
}


chrisch wrote
I'm trying to validate a DateField with a custom validation function that checks if the value of the field is parsed correctly into a Date Object and is not null. Here is my validation function:

var dateValidator = function(value) {
 return (value != null);
}

That works fine so far. The problem is now that the field is not required, the user is allowed to leave it empty. But in this case the value is also null and I cannot determine if the field was intentionally left blank or if the parsing to a date object has failed, because the user has entered a bad string into the date field.

Is there a way to validate it only if the user has entered something?