jenuine Posted September 25, 2011 Share Posted September 25, 2011 I've looked at a number of tutorials and can't figure out what should be a simple regex. I've tried many different ways, and with each change, I'd think "this has to be it", but it never is!! #@$%! Here's a piece of my code: elseif ($size_type == 'mc' && !preg_match("/[0-9]{1,2}x+[0-9]{1,2}/",$itemsize) && !preg_match("/[0-9]{1}(?:XS|XL)/",$itemsize) && !preg_match("/(?:\bXS\b|\bSmall\b|\bMedium\b|\bLarge\b|\bXL\b|[0-9]{1,2})/",$itemsize)) An error message is given if all of these preg_match expressions are false. But it's allowing me to enter "1x" and "123" and "12XL" without error. The first preg_match is supposed to say that there needs to be 1 or 2 digits followed by an "x" followed by 1 or 2 more digits. The second is supposed to allow only 1 digit followed by "XS" or "XL", and the third should allow any of the given words or a 1 or 2 digit number. The curly braces aren't working at all. What is the matter? Also, is there any way to shorten the code and have just a single preg_match? Quote Link to comment https://forums.phpfreaks.com/topic/247816-regex/ Share on other sites More sharing options...
jenuine Posted September 25, 2011 Author Share Posted September 25, 2011 Well, finally I got it working!, like this: elseif ($size_type == 'mc' && !preg_match("/^([0-9]{1,2})x([0-9]{1,2})$/", $itemsize) && !preg_match("/^[0-9]{1}(?:XS|XL)$/",$itemsize) && !preg_match("/^(XS|Small|Medium|Large|XL|[0-9]{1,2})$/",$itemsize)) Quote Link to comment https://forums.phpfreaks.com/topic/247816-regex/#findComment-1272539 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.