// GLOBAL FUNCTIONS function addValidatorToForm(form, submitHandler) { $.validator.addMethod("date", function(value, element) { return this.optional(element) || /^\d{1,2}(\/)\d{1,2}\1\d{4}$/.test(value); }, lang.VAL_DATE); $.validator.addMethod("postalCode", function(value, element) { return this.optional(element) || /^([0-9]{5})|(([a-zA-Z][0-9]){3})$/.test(value); }, lang.VAL_POSTAL_CODE); $.validator.addMethod("numberTwoDecimal", function(value, element) { return this.optional(element) || /^\s*-?(\d+(\.\d{1,2})?|\.\d{1,2})\s*$/.test(value); }, lang.VAL_PRICE_NUMBER_TWO_DECIMAL); $.validator.addMethod("doctorSelect", function(value, element) { return this.optional(element) || value != "-1"; }, lang.VAL_DOCTOR_SELECT); $.validator.addMethod("emailConfirmation", function(value, element) { // Check the "rel" field and compare values var $origEmail = $("#" + $(element).attr("rel")); return $origEmail.val() == value; }, lang.VAL_EMAIL_CONFIRMATION); $.validator.addMethod("passwordConfirmation", function(value, element) { // Check the "rel" field and compare values var $origPassword = $("#" + $(element).attr("rel")); return $origPassword.val() == value; }, lang.VAL_PASSWORD_CONFIRMATION); $.validator.addClassRules({ validateEmail: { email: true, messages: { email: lang.VAL_EMAIL } }, validateEmailConfirm: { email: true, emailConfirmation: true, messages: { email: lang.VAL_EMAIL } }, validatePassword: { minlength: 5, messages: { minlength: lang.VAL_PASSWORD_MINLENGTH } }, validatePasswordConfirm: { minlength: 5, passwordConfirmation: true, messages: { minlength: lang.VAL_PASSWORD_MINLENGTH } }, validatePriceTwoDecimal: { numberTwoDecimal: true }, validateInteger: { digits: true }, validateInteger0to100: { digits: true, min: 0, max: 100, messages: { digits: lang.VAL_0_to_100_DIGITS, min: lang.VAL_0_to_100_DIGITS, max: lang.VAL_0_to_100_DIGITS } }, validateHealthCard: { digits: true, minlength: 10, minlength: 10, messages: { minlength: lang.VAL_10_DIGITS, maxlength: lang.VAL_10_DIGITS } }, validatePostalCode: { postalCode: true }, validateDateOfBirth: { date: true }, validateDate: { date: true }, validateDoctorSelect: { doctorSelect: true } }); //form.validate(); var validator = form.validate({ // Let's ignore hidden fields that are NOT in a tab. If they are in a tab, and are hidden, they should still be validated! ignore: function(){return ($(this).is(":hidden") && $(this).parents(".ui-tabs").length == 0)}, showErrors: function(errorMap, errorList) { this.defaultShowErrors(); /*if (failedHandler != undefined) { failedHandler(); }*/ // Highlight any tabs that have errors. Loop over each tab div, extract the , find the href="#tabs-tabname", check the div with that id and see if there are errors. $("#tabs li a").each(function(){ var id = $(this).attr("href"); id = id.substr(1, id.length); // If the inputs in the tab have errors, assign the "error" class the tab button. if($("div#" + id + " input.error").size() > 0) { $(this).parent().addClass("error"); } else { $(this).parent().removeClass("error"); } }); }, invalidHandler: function(form, validator) { $("div#formValidationFeedback:hidden").fadeIn(500); }, submitHandler: function(form) { $("div#formValidationFeedback:visible").slideUp(300); // This is an optional argument if (submitHandler != undefined) { if(submitHandler()){ form.submit(); //alert($("#processingModalDiv img").attr("src")); //$("#processingModalDiv img").attr("src", "/images/ajaxloadingbar.gif"); //var t=setTimeout('$("#processingModalDiv img").attr("src", "/images/ajaxloadingbar.gif");', 1); } } else{ form.submit(); } } }); $('label.required').append(' 
*
 '); return validator } // VALIDATION METHODS THAT CAN BE ACCESSED OUTSIDE VALIDATOR // CUSTOM VALIDATION METHODS /* function validPostalCode(value) { return /^[A-Za-z]\d[A-Za-z]\d[A-Za-z]\d$/.test(value); } function validZipCode(value) { return /^\d{5}(-\d{4})?$/.test(value); } function validSubdomain(value, element) { return this.optional(element) || /^\w[\w.-]*$/.test(value); } function validPassword(value, element) { return this.optional(element) || /^[^\s]{4,16}$/.test(value); } function validCreditCardSecurity(value, element) { return this.optional(element) || /^\d{3}$/.test(value); } function validPositiveInteger(value, element) { return this.optional(element) || /^\d+$/.test(value); } function validPrice(value, element) { return this.optional(element) || isValidPrice(value); } function validMMDDYYYY(value, element) { return this.optional(element) || isValidMMDDYY(value); } function validDollarValue(value, element) { return this.optional(element) || /^-?\d+(\.\d\d)?$/.test(value); } */ // BIND CUSTOM METHODS /*$.validator.addMethod('postal-code', validPostalCode, msgValidPostalCode); $.validator.addMethod('zip-code', validZipCode, msgValidZipCode); $.validator.addMethod('subdomain', validSubdomain, msgValidSubdomain); $.validator.addMethod('password', validPassword, msgValidPassword); $.validator.addMethod('ccard-csc', validCreditCardSecurity, msgCreditCardSecurity); $.validator.addMethod('positive-integer', validPositiveInteger, msgValidPositiveInteger); $.validator.addMethod('price', validPrice, msgValidPrice); $.validator.addMethod('mmddyy', validMMDDYYYY, msgValidMMDDYYYY); $.validator.addMethod('dollar-value', validDollarValue, msgValidDollarValue);*/