$.validator.methods.min = function(value, element, param) { return (value>param); }; $.validator.addMethod("isValidFullName", function(value) { value = value.trim(); value = value.toUpperCase(); var len = value.length; if(value.indexOf(" ")<2 || value.indexOf("DFG")!=-1 || value.indexOf("FGH")!=-1 || len<5) return(false); if(/[^0-9]+$/i.test(value)==false) return(false); var tmp = value.match(/[AEIOUY]/g); var vowels = tmp ? tmp.length : 0; var tmp = value.match(/[BCDFGHJKLMNÑPQRSTVWXZ]/g); var consonants = tmp ? tmp.length : 0; if(vowels==0 || consonants==0 || (vowels/consonants*100)<5) return false; return(true); }, "The name indicated is incorrect; it must be coherent and composed by the first and last name."); $.validator.addMethod("isValidPassport", function(value) { value = value.trim(); value = value.toUpperCase(); return(true); }, "The document number entered does not seem valid, please check it. We remind you that only documents recognized by the Authorities are accepted."); var userMessage = "The document number entered does not seem valid, please check it. We remind you that only documents recognized by the Authorities are accepted."; var userMessageFunc = function() { return userMessage; }; $.validator.addMethod("isValidPassportNationality", function(passport, element) { nationality = $(element).closest('.form-table').find('.select-nationality').val(); resident = ($(element).closest('.form-table').find('.check-resident').prop('checked')) ? 1 : 0; passport = passport.trim(); passport = passport.toUpperCase(); passport = passport.replace(/ +/g, ''); passport = passport.replace(/\.+/g, ''); passport = passport.replace(/\-+/g, ''); if(nationality=='' || passport=='') return true; var numbers = (passport.match(/\d/g) || []).length; if(nationality!='DE' && nationality!='NL' && numbers<2) // L'Allemagne et la Hollande ne peuvent avoir que des lettres { userMessage = "The document number entered does not seem valid, please check it. We remind you that only documents recognized by the Authorities are accepted."; return false; } if(resident) { var preg = "^([0-9]{6,9}|[0-9]{4}\/[0-9]{2})$"; if(passport.match(preg)==null) { userMessage = "The number entered does not match the valid format for residents. We remind you that if you indicate you are Resident you must be a legal resident in Peru and have an Allien's card (CE) or Immigrant card (CI)."; return false; } return true; } var fmt = []; fmt['IE'] = "[A-Z]{1,2}[0-9]{6,7}"; fmt['NO'] = "[0-9]{8}"; fmt['AR'] = "([A-Z]?[0-9]{7,9}[A-Z]?|[A-Z]{3}[0-9]{6})"; fmt['AU'] = "[A-Z]{1,2}[0-9]{7}"; fmt['AT'] = "[A-Z][0-9]{7,8}"; fmt['BE'] = "[A-Z][A-Z][0-9]{6,7}"; fmt['BR'] = "[A-Z]{0,2}[0-9]{6,12}[A-Z]?"; fmt['CA'] = "[A-Z]{2}[0-9]{6,7}"; fmt['CL'] = "[0-9]{7,10}[A-Z]?"; fmt['CN'] = "[A-Z]{0,2}[0-9]{6,9}"; fmt['CO'] = "[A-Z]{0,2}[0-9]{6,11}"; fmt['CR'] = "[0-9]{9}"; fmt['CZ'] = "[0-9]{8}"; fmt['DK'] = "[0-9]{9}"; fmt['DO'] = "[A-Z]{2}[0-9]{7}"; fmt['EC'] = "([A-Z]?[0-9]{9,10}|[A-Z0-9]*)"; fmt['FI'] = "[A-Z]{0,2}[0-9]{7,8}"; fmt['FR'] = "[0-9]{2}[A-Z]{2}[0-9]{5,6}[A-Z]?"; fmt['DE'] = "([A-Z0-9]*|[0-9]{9,10})"; fmt['GR'] = "[A-Z]{2}[0-9]{7}"; fmt['HK'] = "[A-Z]{1,2}[0-9]{7,8}"; fmt['HU'] = "[A-Z]{1,2}[0-9]{6,8}"; fmt['IS'] = "[A-Z][0-9]{7}"; fmt['IN'] = "[A-Z][0-9]{7,8}"; fmt['IL'] = "[0-9]{7,8}"; fmt['IT'] = "[A-Z]{0,2}[0-9]{6,8}[A-Z]?"; fmt['JP'] = "[A-Z]{2}[0-9]{7}"; fmt['KR'] = "[A-Z]?[A-Z]?[0-9]{7,8}"; fmt['MY'] = "[A-Z][0-9]{8}"; fmt['MX'] = "[A-Z]?[0-9]{8,12}"; fmt['NL'] = "[A-Z]{2}[A-Z0-9]{7}"; fmt['NZ'] = "[A-Z]{1,2}[0-9]{6}"; fmt['PA'] = "[A-Z]{0,2}[0-9]{7}"; fmt['PE'] = "(PC[0-9]{5}|[0-9]{7,8})"; fmt['PL'] = "[A-Z]{2}[0-9]{7}"; fmt['PT'] = "[A-Z]{1,2}[0-9]{6,7}"; fmt['PR'] = "[0-9]{7,9}"; fmt['RU'] = "[0-9]{2}[A-Z]?[0-9]{7}"; fmt['SG'] = "[A-Z][0-9]{7}[A-Z]"; fmt['ZA'] = "[A-Z]?[0-9]{8,9}[A-Z]?"; fmt['ES'] = "[A-Z]{0,3}[0-9]{6,10}[A-Z]?"; fmt['SE'] = "[A-Z]{0,2}[0-9]{7,8}"; fmt['CH'] = "[A-Z][0-9]{7}"; fmt['TW'] = "[0-9]{9}"; fmt['GB'] = "[0-9]{9}"; fmt['US'] = "[A-Z]{0,2}[0-9]{8,11}"; fmt['VE'] = "[A-Z]?[0-9]{7,9}"; if(fmt[nationality]==null) return true; preg = "^("+fmt[nationality]+")$"; if(passport.match(preg)==null) { userMessage = "The document number entered does not match the valid format of the country you indicated. Please check the entered number and nationality. We remind you that only documents recognized by the Authorities are accepted."; return false; } return true; }, userMessageFunc); $.validator.addMethod("isValidPhone", function(phone_number, element) { phone_number = phone_number.replace(/(\.|\-|\ )/g, ''); return this.optional(element) || phone_number.length > 6 && phone_number.match(/^(\+?[0-9]{7,12})$/); }, "The phone number is not valid."); $.validator.addMethod("isValidID", function(id, element) { if(id=='' || this.optional(element)) return true; var retval = false; $.ajax({ url: '/general/scripts/check_valid_id.php?id='+id, async: false, dataType: 'text', success: function(data) { retval = (data=='1'); }, error: function(data) { retval = false; } }); return(retval); }, "The reservation/purchase number doesn't correpond to any file."); $.validator.addMethod("FullNameRequired", $.validator.methods.required, "You haven't indicated the name."); $.validator.addMethod("FullNameMinlength", $.validator.methods.minlength, "You must indicate the full name (first and last name)."); $.validator.addClassRules("FullNameCheck", { FullNameRequired: true, FullNameMinlength: 5, isValidFullName: true }); $.validator.addMethod("EmailRequired", $.validator.methods.required, "You haven't indicated the email."); $.validator.addMethod("EmailValid", $.validator.methods.email, "The email entered is not valid."); $.validator.addClassRules("EmailCheck", { EmailRequired: true, EmailValid: true }); $.validator.addMethod("PassportRequired", $.validator.methods.required, "You haven't indicated the document number."); $.validator.addMethod("PassportMinlength", $.validator.methods.minlength, "The document number entered is not valid."); $.validator.addClassRules("PassportCheck", { PassportRequired: true, PassportMinlength: 6, isValidPassport: true }); $.validator.addClassRules("PassportNationalityCheck", { isValidPassportNationality: true }); $.validator.addMethod("BookNumberRequired", $.validator.methods.required, "You haven't indicated the number."); $.validator.addMethod("BookNumberNumeric", $.validator.methods.number, "The number entered is not valid."); $.validator.addMethod("BookNumberMinlength", $.validator.methods.minlength, "The number entered is not valid."); $.validator.addClassRules("BookNumberCheck", { BookNumberRequired: true, BookNumberNumeric: true, BookNumberMinlength: 6 }); $.validator.addClassRules("IDCheck", { BookNumberNumeric: true, BookNumberMinlength: 6 , isValidID: true }); $.validator.addMethod("PhoneNumberRequired", $.validator.methods.required, "You haven't entered your phone number."); $.validator.addClassRules("PhoneNumberCheck", { PhoneNumberRequired: true, isValidPhone: true }); $.validator.addMethod("AddressRequired", $.validator.methods.required, "You haven't entered your address."); $.validator.addClassRules("AddressCheck", { AddressRequired: true }); $.validator.addMethod("CityRequired", $.validator.methods.required, "You haven't entered your residence city."); $.validator.addClassRules("CityCheck", { CityRequired: true });