Regular Expression working on regexr but not in PHP |
Hello, i want to use regex to validate the coupon format. I wrote the rules on regexr.com and it worked fine but not in php.
The expression i have: ([0-9]{3})+(-)+([0-9A-Z]{3})+(-)+([A-Z]{3}) Coupon format: 230-4WE-GAG 424-423-NJB Basically the first 3 digits are numbers followed by a dash then 3 alphanumeric digits followed by a dash and at the end 3 characters And the code i have: PHP Code: if (preg_match('/([0-9]{3})+(-)+([0-9A-Z]{3})+(-)+([A-Z]{3})/', $coupon)) { I know that PHP treats regex a little bit different but in which way?
The regex in your php code is not the same regex you posted in "The expression i have". Check the parenthesis. You're missing some.
I think you should append and prepend '#' in your string instead of '/'
NexoPOS 2.6.2 available on CodeCanyon.
Try
PHP Code: preg_match('/[0-9]{3}-[A-Z0-9]{3}-[A-Z]{3}/', $coupon) 3 digits followed by dash followed by mixture of 3 digits and/or A-Z chars followed by dash followed by 3 chars A-Z |
Welcome Guest, Not a member yet? Register Sign In |