porzant Posted June 28, 2007 Share Posted June 28, 2007 <?php// The "i" after the pattern delimiter indicates a case-insensitive searchif (preg_match("/^([0-9]{1}|[0-9]{2})-[a-z]{3}, [0-9]{2}:[0-9]{2} GMT$/i", "01-Jun, 13:30 GMT")) {if(preg_match("/[A-Z0-9 _-]{3,12}/i", "abcdefghijklm")){ echo "A match was found.";} }else { echo "A match was not found.";}?> First section works fine. On the second section, {3,12} means it should match those charactes for a minimum of 3 and a maximum of 12 times doesn't it? When there are 13 characters, it still returns the match as true. Anyone know why? Link to comment Share on other sites More sharing options...
Mr_CHISOL Posted June 28, 2007 Share Posted June 28, 2007 The thing is that that reg.exp (/[A-Z0-9 _-]{3,12}/i) matches a substring/section of the string and not nessassary the whole string. (/abc/ matches "abc", "aabc", "123abc456" etc.). To make it to only match the whole string you need to add ^ (matches the beginning of the string) and $ (matches the end of the string) (just as you have in the first reg.exp. The regexp would the look like this:/^[A-Z0-9 _-]{3,12}$/iOr in the code: <?php// The "i" after the pattern delimiter indicates a case-insensitive searchif (preg_match("/^([0-9]{1}|[0-9]{2})-[a-z]{3}, [0-9]{2}:[0-9]{2} GMT$/i", "01-Jun, 13:30 GMT")) { if(preg_match("/^[A-Z0-9 _-]{3,12}$/i", "abcdefghijklm")) { echo "A match was found."; }} else { echo "A match was not found.";}?> Good Luck and Don't Panic! ;?) Link to comment Share on other sites More sharing options...
porzant Posted June 28, 2007 Author Share Posted June 28, 2007 Ah, forgot about them. Thanks for the help Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.