Welcome Guest, Not a member yet? Register   Sign In
Regular Expression working on regexr but not in PHP
#1

(This post was last modified: 06-13-2015, 08:15 AM by FlevasGR.)

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)) {            
     
$coupon_data $this->coupons->check_coupon($coupon);
     
$this->response($coupon_data200);

(i'm using the rest library)

I know that PHP treats regex a little bit different but in which way?
Reply


Messages In This Thread
Regular Expression working on regexr but not in PHP - by FlevasGR - 06-13-2015, 08:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB