Aureole Posted February 6, 2008 Share Posted February 6, 2008 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. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 6, 2008 Share Posted February 6, 2008 <script> var code = 'ABC123'; var hexRegex = /^[a-fA-F0-9]{6}$/; if(code.match(hexRegex)) document.write(code + ' matches'); </script> Quote Link to comment Share on other sites More sharing options...
Aureole Posted February 6, 2008 Author Share Posted February 6, 2008 Thank you very much, will that work for all possible hexadecimal colour codes? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 6, 2008 Share Posted February 6, 2008 should Quote Link to comment Share on other sites More sharing options...
mainewoods Posted February 8, 2008 Share Posted February 8, 2008 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.