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?