Last active
January 23, 2017 12:54
-
-
Save FabianoFaria/6d5b5f11c3566bfad16564482b38331b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.validator.addMethod("greaterThan", | |
function(value, element, params) { | |
if (!/Invalid|NaN/.test(new Date(value))) { | |
return new Date(value) > new Date($(params).val()); | |
} | |
return isNaN(value) && isNaN($(params).val()) | |
|| (Number(value) > Number($(params).val())); | |
},'Must be greater than {0}.'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.validator.addMethod("dateBR", function(value, element) { | |
if(value.length!=10) return false; | |
var data = value; | |
var dia = data.substr(0,2); | |
var barra1 = data.substr(2,1); | |
var mes = data.substr(3,2); | |
var barra2 = data.substr(5,1); | |
var ano = data.substr(6,4); | |
if(data.length!=10||barra1!="/"||barra2!="/"||isNaN(dia)||isNaN(mes)||isNaN(ano)||dia>31||mes>12)return false; | |
if((mes==4||mes==6||mes==9||mes==11) && dia==31)return false; | |
if(mes==2 && (dia>29||(dia==29 && ano%4!=0)))return false; | |
if(ano < 1900)return false; | |
return true; | |
}, "Informe uma data válida."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.validator.addMethod("formatoHorario", function(value, element) { | |
re = /^\d{1,2}:\d{2}([ap]m)?$/; | |
var isValid = /^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/.test(value); | |
if (isValid) { | |
return true; | |
} else { | |
return false; | |
} | |
}, "Favor informar um horário corretamente!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery.validator.addMethod("dataMenorQuehoje", function(value, element) { | |
if (value != undefined || value != '') { | |
var dataVenCheck = value.split('/'); | |
var diaHoje = new Date(); | |
var comparaData = new Date(dataVenCheck[2]+'/'+dataVenCheck[1]+'/'+dataVenCheck[0]); | |
//NECESSARIO PARA QUE SEJA CONPARADO APENAS DIA, MÊS E ANO | |
diaHoje.setHours(0,0,0,0); | |
if(comparaData.valueOf() == diaHoje.valueOf()){ | |
return true; | |
} | |
else if( comparaData > diaHoje){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
}else{ | |
return false; | |
} | |
}, "Favor informar uma data maior que a de hoje!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment