mac.js 859 B

12345678910111213141516171819202122232425
  1. (function($) {
  2. $.fn.bootstrapValidator.i18n.mac = $.extend($.fn.bootstrapValidator.i18n.mac || {}, {
  3. 'default': 'The value is not a valid MAC address'
  4. });
  5. $.fn.bootstrapValidator.validators.mac = {
  6. /**
  7. * Return true if the input value is a MAC address.
  8. *
  9. * @param {BootstrapValidator} validator The validator plugin instance
  10. * @param {jQuery} $field Field element
  11. * @param {Object} options Can consist of the following keys:
  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-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
  21. }
  22. };
  23. }(window.jQuery));