hex.js 847 B

12345678910111213141516171819202122232425
  1. (function($) {
  2. $.fn.bootstrapValidator.i18n.hex = $.extend($.fn.bootstrapValidator.i18n.hex || {}, {
  3. 'default': 'Please enter a valid hexadecimal number'
  4. });
  5. $.fn.bootstrapValidator.validators.hex = {
  6. /**
  7. * Return true if and only if the input value is a valid hexadecimal number
  8. *
  9. * @param {BootstrapValidator} validator The validator plugin instance
  10. * @param {jQuery} $field Field element
  11. * @param {Object} options Consist of key:
  12. * - message: The invalid message
  13. * @returns {Boolean}
  14. */
  15. validate: function(validator, $field, options) {
  16. var value = $field.val();
  17. if (value === '') {
  18. return true;
  19. }
  20. return /^[0-9a-fA-F]+$/.test(value);
  21. }
  22. };
  23. }(window.jQuery));