isValidHex.js 253 B

1234567891011
  1. 'use strict';
  2. /**
  3. * Check if a value is a valid 3, 4, 6 or 8 digit hex
  4. *
  5. * @param {string} value
  6. * @returns {boolean}
  7. */
  8. module.exports = function isValidHex(value) {
  9. return /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value);
  10. };