Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save thyagorafaell/35b1d7a994adf10f61e9 to your computer and use it in GitHub Desktop.

Select an option

Save thyagorafaell/35b1d7a994adf10f61e9 to your computer and use it in GitHub Desktop.
Some useful jQuery Validation methods.
(function(moment, $) {
$.validator.addMethod('datetime', function(value, element) {
if (value === '__/__/__ __:__' || value === '') {
return true;
}
return moment(value, 'DD/MM/YYYY HH:mm', true).isValid();
}, '');
$.validator.addMethod('date', function(value, element) {
if (value === '__/__/__ __:__' || value === '') {
return true;
}
return moment(value, 'DD/MM/YYYY HH:mm').isValid();
}, '');
$.validator.addMethod('time-report', function(value, element) {
if (value === '__:__' || value === '') {
return true;
}
return moment(value, 'h:mm').isValid();
}, '');
$.validator.addMethod('time', function(value, element) {
if (value === '__:__' || value === '') {
return true;
}
return moment(value, 'HH:mm').isValid();
}, '');
}(moment, window.jQuery));
!function(_,t){t.validator.addMethod("datetime",function(t){return"__/__/__ __:__"===t||""===t?!0:_(t,"DD/MM/YYYY HH:mm",!0).isValid()},""),t.validator.addMethod("date",function(t){return"__/__/__ __:__"===t||""===t?!0:_(t,"DD/MM/YYYY HH:mm").isValid()},""),t.validator.addMethod("time-report",function(t){return"__:__"===t||""===t?!0:_(t,"h:mm").isValid()},""),t.validator.addMethod("time",function(t){return"__:__"===t||""===t?!0:_(t,"HH:mm").isValid()},"")}(moment,window.jQuery)
(function(moment, $) {
$.validator.addMethod('datetime', function(value, element) {
if (value === '__/__/__ __:__' || value === '') {
return true;
}
return moment(value, 'MM/DD/YYYY HH:mm', true).isValid();
}, '');
$.validator.addMethod('date', function(value, element) {
if (value === '__/__/__ __:__' || value === '') {
return true;
}
return moment(value, 'MM/DD/YYYY HH:mm').isValid();
}, '');
$.validator.addMethod('time-report', function(value, element) {
if (value === '__:__' || value === '') {
return true;
}
return moment(value, 'h:mm').isValid();
}, '');
$.validator.addMethod('time', function(value, element) {
if (value === '__:__' || value === '') {
return true;
}
return moment(value, 'HH:mm').isValid();
}, '');
}(moment, window.jQuery));
!function(_,t){t.validator.addMethod("datetime",function(t){return"__/__/__ __:__"===t||""===t?!0:_(t,"MM/DD/YYYY HH:mm",!0).isValid()},""),t.validator.addMethod("date",function(t){return"__/__/__ __:__"===t||""===t?!0:_(t,"MM/DD/YYYY HH:mm").isValid()},""),t.validator.addMethod("time-report",function(t){return"__:__"===t||""===t?!0:_(t,"h:mm").isValid()},""),t.validator.addMethod("time",function(t){return"__:__"===t||""===t?!0:_(t,"HH:mm").isValid()},"")}(moment,window.jQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment