Check whether text is a valid hex code

The rules to be a valid hexadecimal code are:

  1. It should start from ‘#’ symbol.
  2. It should be followed by the letters from a-f, A-F and/or digits from 0-9.
  3. The length of the hexadecimal color code should be either 6 or 3, excluding ‘#’ symbol.
2 Likes