Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    377
    Thanks
    8
    Thanked 1 Time in 1 Post

    Check color hex code with Javascript

    Hello,

    How can I validate a form field if the visitor has entered a valid hex color code between #000000 and #FFFFFF?

    Thanks in advance.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,917
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    if (/^(#[A-F0-9]{6})$/i.test(lstr.value)) { // valid hex code

    You can test your regular expressions at: http://www.ogauge.co.uk/regextester.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •