Skip to content

Instantly share code, notes, and snippets.

@daxburatto
daxburatto / Validating a Hex Value.md
Last active February 2, 2025 10:02
Validating a Hex Value with Regex

Validating a Hex Value

/^#?([a-f0-9]{6}|[a-f0-9]{3})$/

Summary

A Regular expression, or Regex, is a method of validating a specific piece of text by use of a sequence of characters each including their own fundimental principles. Regex can be used to validate emails, hex values, URLs, and HTML. In this case we will be focusing on Hex values which are typically a # with 6 numbers or letters following it.

Table of Contents