-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
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);andif (isNaN(colorValue) || colorValue < 0 || colorValue > 16777215){}
Metadata
Metadata
Assignees
Labels
No labels