this.user Posted October 30, 2009 Share Posted October 30, 2009 I want to use preg_match to make sure a string is always 6 characters long and only contains 0-9 and the letters A-F. I have this but it does not work: '/^[0-9A-F]{6}$/' Link to comment https://forums.phpfreaks.com/topic/179591-preg_match-question/ Share on other sites More sharing options...
cags Posted October 30, 2009 Share Posted October 30, 2009 Hmm... that pattern looks right. Can we see the code just in case there's an error there. Also some data you think should match but doesn't. Link to comment https://forums.phpfreaks.com/topic/179591-preg_match-question/#findComment-947759 Share on other sites More sharing options...
salathe Posted October 30, 2009 Share Posted October 30, 2009 If there are any lowercase letters, you'll likely need to make the pattern case-insensitive (with the i modifier) or extend the character class to include lowercase letters: /^[0-9A-F]{6}$/Di or /^[0-9a-fA-F]{6}$/D respectively (note both use the D modifier, more info). Link to comment https://forums.phpfreaks.com/topic/179591-preg_match-question/#findComment-947761 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.