Skip to content

Instantly share code, notes, and snippets.

View christiangella's full-sized avatar

Manong Chris christiangella

  • Occupied Patwin Land
  • 19:43 (UTC -07:00)
View GitHub Profile
@christiangella
christiangella / hexcodemethods.md
Last active January 23, 2023 19:51
Regex Validation of Hex Codes

Regex Validation of Hex Codes

This GitHub Gist will cover the Regular Expression methodology in validating hexadecimal colors codes.

A regex is a sequence of characters, or a string, that localizes and designates a specific pattern to a specific outcome. The utility of regex allows for the compression and streamlining of code into a smaller function, querying and modifying specific strings, and validating data against parameters. The specific function of regex within hex codes is to both consolidate code into a six-digit value and ensure that this value meets the defined parameters.

A hexadecimal is a numerical system with a base value of sixteen (base-16). They are represented by the values 0-9 (0,1,2,3,4,5,6,7,8,9) which represent the numerical values 0-9, and A-F (A,B,C,D,E,F) which represent the numerical values 10-15. One such application of hexadecimal values are hex color codes. These are six-digit hexadecimal values that are mapped to Red-Green-Blue (hereafter: RGB) va