$.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); }, "El nombre indicado es incorrecto; tiene que ser coherente y compuesto por nombre y apellido."); $.validator.addMethod("isValidPassport", function(value) { value = value.trim(); value = value.toUpperCase(); return(true); }, "El número de documento indicado no parece ser válido, por favor verifíquelo. Le recordamos que solo los documentos reconocidos por las Autoridades son aceptados."); var userMessage = "El número de documento indicado no parece ser válido, por favor verifíquelo. Le recordamos que solo los documentos reconocidos por las Autoridades son aceptados."; 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 = "El número de documento indicado no parece ser válido, por favor verifíquelo. Le recordamos que solo los documentos reconocidos por las Autoridades son aceptados."; return false; } if(resident) { var preg = "^([0-9]{6,9}|[0-9]{4}\/[0-9]{2})$"; if(passport.match(preg)==null) { userMessage = "El número indicado no corresponde al formato en vigencia para residentes. Le recordamos que si usted indica que es Residente debe tener la residencia legal en Perú y un carné de extranjería (CE) o de inmigrante (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 = "El número de documento indicado no corresponde al formato vigente del país indicado. Por favor verifique el número y la nacionalidad ingresados. Le recordamos que solo los documentos reconocidos por las Autoridades son aceptados."; 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})$/); }, "El número de teléfono no es válido."); $.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); }, "El número de reserva/compra no corresponde a ningún expediente."); $.validator.addMethod("FullNameRequired", $.validator.methods.required, "No ha indicado el nombre."); $.validator.addMethod("FullNameMinlength", $.validator.methods.minlength, "Debe indicar el nombre completo (nombre y apellido)."); $.validator.addClassRules("FullNameCheck", { FullNameRequired: true, FullNameMinlength: 5, isValidFullName: true }); $.validator.addMethod("EmailRequired", $.validator.methods.required, "No ha indicado el email."); $.validator.addMethod("EmailValid", $.validator.methods.email, "La dirección email es incorrecta."); $.validator.addClassRules("EmailCheck", { EmailRequired: true, EmailValid: true }); $.validator.addMethod("PassportRequired", $.validator.methods.required, "No ha indicado el número de documento."); $.validator.addMethod("PassportMinlength", $.validator.methods.minlength, "El número de documento indicado no es válido."); $.validator.addClassRules("PassportCheck", { PassportRequired: true, PassportMinlength: 6, isValidPassport: true }); $.validator.addClassRules("PassportNationalityCheck", { isValidPassportNationality: true }); $.validator.addMethod("BookNumberRequired", $.validator.methods.required, "No ha indicado el número."); $.validator.addMethod("BookNumberNumeric", $.validator.methods.number, "El número es incorrecto."); $.validator.addMethod("BookNumberMinlength", $.validator.methods.minlength, "El número es incorrecto."); $.validator.addClassRules("BookNumberCheck", { BookNumberRequired: true, BookNumberNumeric: true, BookNumberMinlength: 6 }); $.validator.addClassRules("IDCheck", { BookNumberNumeric: true, BookNumberMinlength: 6 , isValidID: true }); $.validator.addMethod("PhoneNumberRequired", $.validator.methods.required, "No ha indicado su número de teléfono."); $.validator.addClassRules("PhoneNumberCheck", { PhoneNumberRequired: true, isValidPhone: true }); $.validator.addMethod("AddressRequired", $.validator.methods.required, "No ha indicado su dirección."); $.validator.addClassRules("AddressCheck", { AddressRequired: true }); $.validator.addMethod("CityRequired", $.validator.methods.required, "No ha indicado su ciudad de residencia."); $.validator.addClassRules("CityCheck", { CityRequired: true });