Skip to content

➡ HEX Formatting #6

Description

@izzycodes02

Check if the text that the user inputs is an actual HEX code by testing if it's in the HEX code formatting.

Solution

  • Use hexCodeFormat = /^#?([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$/; as the variable to test the input text against
  • Use .test() to test the input text
  • If the input text is not in that format, show an error message of "Incorrect HEX code!"
  • The new if-statement show occurs after the '#' is at the front of the input text

Bonus ✨

  • Check if the input text is a valid HEX code, not just formatted in a way
  • Try var colorValue = parseInt(hexCode.slice(1), 16); and if (isNaN(colorValue) || colorValue < 0 || colorValue > 16777215){}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions