/** * Return true, if the value is a valid date, also making this formal check mm/dd/yyyy. * * @example jQuery.validator.methods.date("01/01/1900") * @result true * * @example jQuery.validator.methods.date("13/01/1990") * @result false * * @example jQuery.validator.methods.date("01.01.1900") * @result false * * @example * @desc Declares an optional input element whose value must be a valid date. * * @name jQuery.validator.methods.dateUS * @type Boolean * @cat Plugins/Validate/Methods */ jQuery.validator.addMethod( "dateUS", function(value, element) { var check = false; var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/; if( re.test(value)){ var adata = value.split('/'); var mm = parseInt(adata[0],10); var dd = parseInt(adata[1],10); var yyyy = parseInt(adata[2],10); var xdata = new Date(yyyy,mm-1,dd); if ( ( xdata.getFullYear() == yyyy ) && ( xdata.getMonth () == mm - 1 ) && ( xdata.getDate() == dd ) ) check = true; else check = false; } else check = false; return this.optional(element) || check; }, "Please enter a date in the format mm/dd/yyyy" ); /* add type="questionMarkInvalid" to any form field to disallow "?" as a valid selection */ jQuery.validator.addMethod( "questionMarkInvalid", function(value, element) { if ( value != '' && value != '?' ) { return true; } else { return false; } }, "Required field" ); /* add fsephone to the class, not the type! setting type messes up the format. adding to class also makes it required. */ jQuery.validator.addMethod( "fsephone", function(value, element) { var _normalized = value.replace(/\D/g, ""); if (_normalized.length != 10) { return false; } else { //var _rePhone = /^(\(\d{3}\)\s*|\d{3}[-.])\d{3}[-.]\d{4}(\s+.*)?$/; var _rePhone = /^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/; return _rePhone.test( value ); } }, "Please enter phone in the format nnn-nnn-nnnn" ); /* add type="fseDecimal" to any form field will enforce numbers and accept leading decimal, such as ".5". type="number" will invalidate ".5". example: class="required fsedecimal" */ jQuery.validator.addMethod( "fsedecimal", function(value, element) { var re = /^-?(?:\d*|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/; if( re.test(value)){ return true; } else { return false; } }, "Required field" );