Jump to content

Need a regular expression


Aureole

Recommended Posts

I need a regular expression written in Javascript for A-Z/0-9/6 Characters, yes it's for hexa-decimal colour codes.

 

If it's possible to do it with jQuery then that's great, if not then that's fine.

 

I searched Google and I can't find anything, any help is very much appreciated.

Link to comment
Share on other sites

3 dight hex codes are also allowed:

.mystyle {color:#ccc; /* gray color, will be interpreted as #cccccc */ }

<script>
  var code = 'ABC123';
  var hexRegex = /^[a-fA-F0-9]{6}$/;
  var hexRegex3 = /^[a-fA-F0-9]{3}$/; // test for valid 3 dight hex

  if(code.match(hexRegex) || code.match(hexRegex3))
    document.write(code + ' matches');
</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.