mac.js 702 B

123456789101112131415161718192021
  1. (function($) {
  2. $.fn.bootstrapValidator.validators.mac = {
  3. /**
  4. * Return true if the input value is a MAC address.
  5. *
  6. * @param {BootstrapValidator} validator The validator plugin instance
  7. * @param {jQuery} $field Field element
  8. * @param {Object} options Can consist of the following keys:
  9. * - message: The invalid message
  10. * @returns {Boolean}
  11. */
  12. validate: function(validator, $field, options) {
  13. var value = $field.val();
  14. if (value == '') {
  15. return true;
  16. }
  17. return /^([0-9A-F]{2}[:-]){5}([0-9A-F]{2})$/.test(value);
  18. }
  19. };
  20. }(window.jQuery));