Check whether the string is a hex - Node.js String

Node.js examples for String:Parse

Description

Check whether the string is a hex

Demo Code

/*// w  w w  . j a va 2  s  .  c  o  m
  Check whether the string is a hex - e.g. #FF00FF or #FFF.
\
  @param {this} The string to check.
  @return {boolean} Whether the string is a hex or not.
*/
String.prototype.isHex = function() {

  return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(this);

};

Related Tutorials