Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Validacion para campos en la que se ingresará empresas, acepta letras con tilde o sin tilde, ampersands y puntos
- jQuery.validator.addMethod("valiEmpresa", function(value, element) {
- return this.optional(element) || /^[a-zA-Z0-9&.áéíóúÁÉÍÓÚäëïöüÄËÏÖÜàèìòùÀÈÌÒÙñÑ]*$/.test(value);
- });
- //Validacion para campos que contengan paginas web
- jQuery.validator.addMethod("valiWeb", function(value, element) {
- return this.optional(element) || /^[a-zA-Z0-9]+[a-zA-Z0-9-\.]*(\.[a-zA-Z]{2,3})$/.test(value);
- });
- //validacion para campos que contengan direccion
- jQuery.validator.addMethod("valiDireccion", function(value, element) {
- return this.optional(element) || /^[a-zA-Z0-9.&//áéíóúÁÉÍÓÚäëïöüÄËÏÖÜàèìòùÀÈÌÒÙñÑ]*$/.test(value);
- });
- //validacion para campos que contenga email
- jQuery.validator.addMethod("valiEmail", function(value, element) {
- return this.optional(element) || /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/.test(value);
- });
- //validacion para combos simple
- $.validator.addMethod('selectnone',function(value, element) {
- return this.optional(element) || (value!='seleccione');
- }, "Seleccione una opcion");
- //Validación sólo letras en mayúsculas/minúsculas, acentudadas, espacios , punto, coma. No admite cadena vacía
- function validaran(e){
- obj=e.srcElement || e.target;
- tecla_codigo = (document.all) ? e.keyCode : e.which;
- if(tecla_codigo==8)return true;
- patron =/^[a-zA-ZáéíóúÁÉÍÓÚäëïöüÄËÏÖÜàèìòùÀÈÌÒÙñÑ\s.,0-9]+$/;
- tecla_valor = String.fromCharCode(tecla_codigo);
- return patron.test(tecla_valor);
- }
- //Validación para monto mayor a 0
- $.validator.addMethod("morethan0", function(value, element) {
- return this.optional(element) || (parseFloat(value) > 0);
- }, "* El monto debe ser mayor a 0");
- //Validación solo números, no se admite cadena vacía
- function validarn(e){
- obj=e.srcElement || e.target;
- tecla_codigo = (document.all) ? e.keyCode : e.which;
- if(tecla_codigo==8)return true;
- patron =/^[0-9]+$/;
- tecla_valor = String.fromCharCode(tecla_codigo);
- return patron.test(tecla_valor);
- }
- //Validación fecha formato yyy/mm/dd ( si se quiere cambiar solo mover 4 y 1,2)
- $.validator.addMethod("formatfecha", function(value, element) {
- return value.match(/^(\d{4}\-\d{1,2}\-\d{1,2})$/);
- }, "Por favor ingrese un formato valido");
- //Validacion para DNI + maxlength="8"
- function validarsolon(e){
- obj=e.srcElement || e.target;
- tecla_codigo = (document.all) ? e.keyCode : e.which;
- if(tecla_codigo==8)return true;
- patron =/[0-9]/;
- tecla_valor = String.fromCharCode(tecla_codigo);
- control=(tecla_codigo==46 && (/[.]/).test(obj.value))?false:true
- return patron.test(tecla_valor) && control;
- }
- //Validación para solo letras
- function validarsolol(e){
- obj=e.srcElement || e.target;
- tecla_codigo = (document.all) ? e.keyCode : e.which;
- if(tecla_codigo==8)return true;
- patron =/^[a-zA-ZñÑáéíóúÁÉÍÓÚ]+$/;
- tecla_valor = String.fromCharCode(tecla_codigo);
- return patron.test(tecla_valor);
- }
- -----------------------------------------------------------------------------------------------------------------
- function validate(evt) {
- var theEvent = evt || window.event;
- var key = theEvent.keyCode || theEvent.which;
- key = String.fromCharCode( key );
- var regex = /[0-9]/;
- if( !regex.test(key) ) {
- theEvent.returnValue = false;
- if(theEvent.preventDefault) theEvent.preventDefault();
- }
- }
- <input type="text" id="units" name="units" onkeypress="validate(event)" maxlength="3">
- function validarn(e){
- obj=e.srcElement || e.target;
- tecla_codigo = (document.all) ? e.keyCode : e.which;
- if(tecla_codigo==8)return true;
- patron =/[0-9.]/;
- tecla_valor = String.fromCharCode(tecla_codigo);
- control=(tecla_codigo==46 && (/[.]/).test(obj.value))?false:true
- return patron.test(tecla_valor) && control;
- }
- function validaran(e){
- obj=e.srcElement || e.target;
- tecla_codigo = (document.all) ? e.keyCode : e.which;
- if(tecla_codigo==8)return true;
- patron =/^[a-zA-ZñÑáéíóúÁÉÍÓÚ\s.,0-9]+$/;
- tecla_valor = String.fromCharCode(tecla_codigo);
- return patron.test(tecla_valor);
- }
- function validarnum(e){
- obj=e.srcElement || e.target;
- tecla_codigo = (document.all) ? e.keyCode : e.which;
- if(tecla_codigo==8)return true;
- patron =/^[0-9]+$/;
- tecla_valor = String.fromCharCode(tecla_codigo);
- return patron.test(tecla_valor);
- }
- function validarsolon(e){
- obj=e.srcElement || e.target;
- tecla_codigo = (document.all) ? e.keyCode : e.which;
- if(tecla_codigo==8)return true;
- patron =/[0-9]/;
- tecla_valor = String.fromCharCode(tecla_codigo);
- control=(tecla_codigo==46 && (/[.]/).test(obj.value))?false:true
- return patron.test(tecla_valor) && control;
- }
- function validarsolol(e){
- obj=e.srcElement || e.target;
- tecla_codigo = (document.all) ? e.keyCode : e.which;
- if(tecla_codigo==8)return true;
- patron =/^[a-zA-ZñÑáéíóúÁÉÍÓÚ]+$/;
- tecla_valor = String.fromCharCode(tecla_codigo);
- return patron.test(tecla_valor);
- }
- Funcional::::::::::::::::::::::::::
- Solo numeros
- <input type='text' onkeypress='validate(event)' />
- function validate(evt) {
- var theEvent = evt || window.event;
- var key = theEvent.keyCode || theEvent.which;
- key = String.fromCharCode( key );
- var regex = /[0-9]|\./;
- if( !regex.test(key) ) {
- theEvent.returnValue = false;
- if(theEvent.preventDefault) theEvent.preventDefault();
- }
- }
- Datepicker bug:
- $(function() {
- $( "#jQueryValidateTest" ).validate();
- $( "[type=date]" ).datepicker({
- onClose: function() {
- $( this ).valid();
- }
- });
- });
- ADD METHODS:
- $.validator.addMethod("lettersonly", function(value, element) {
- return this.optional(element) || /^[a-z\s]+$/i.test(value);
- }, "Solo ingrese letras");
- $.validator.addMethod('selectnone',function(value, element) {
- return this.optional(element) || (value!='seleccione');
- }, "Seleccione una opcion");
- $.validator.addMethod("morethan0", function(value, element) {
- return this.optional(element) || (parseFloat(value) > 0);
- }, "* El monto debe ser mayor a 0");
- $.validator.addMethod("formatfecha", function(value, element) {
- return value.match(/^(\d{4}\-\d{1,2}\-\d{1,2})$/);
- }, "Por favor ingrese un formato valido");
Advertisement
Add Comment
Please, Sign In to add comment