isMACAddress.js 582 B

12345678910111213141516
  1. import assertString from './util/assertString';
  2. var macAddress = /^(?:[0-9a-fA-F]{2}([-:\s]))([0-9a-fA-F]{2}\1){4}([0-9a-fA-F]{2})$/;
  3. var macAddressNoSeparators = /^([0-9a-fA-F]){12}$/;
  4. var macAddressWithDots = /^([0-9a-fA-F]{4}\.){2}([0-9a-fA-F]{4})$/;
  5. export default function isMACAddress(str, options) {
  6. assertString(str);
  7. /**
  8. * @deprecated `no_colons` TODO: remove it in the next major
  9. */
  10. if (options && (options.no_colons || options.no_separators)) {
  11. return macAddressNoSeparators.test(str);
  12. }
  13. return macAddress.test(str) || macAddressWithDots.test(str);
  14. }