Guest User

Untitled

a guest
Aug 16th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. How to check if a string is a valid hex color representation?
  2. var isOk = /^#[0-9A-F]{6}$/i.test('#aabbcc')
  3.  
  4. var isOk = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test('#ac3') // for #f00 (Thanks Smamatti)
  5.  
  6. function isHexaColor(sNum){
  7. return (typeof sNum === "string") && sNum.length === 6
  8. && ! isNaN( parseInt(sNum, 16) );
  9. }
Add Comment
Please, Sign In to add comment