Jump to content

Need a regular expression


Aureole

Recommended Posts

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.