Page 1 of 1

preg_match problem

Posted: Sat Feb 26, 2011 6:27 pm
by gd77
if(!preg_match('/^(([\+]+[0-9]{2,3})+([\-][0-9]{1,2})+([\-][0-9]{3}){2})$/',$txt)){......}

$txt will be matching +584-69-589-985. pattern: +xxx-xx-xxx-xxx
As regular ex.the code works fine but in php preg_match it doesn't.

Re: preg_match problem

Posted: Sun Feb 27, 2011 3:12 am
by Christopher
Do you really want all of those sub-patterns? How about just:

/^[\+][0-9]{2,3}[\-][0-9]{1,2}[\-][0-9]{3}[\-][0-9]{3}$/

Re: preg_match problem

Posted: Sun Feb 27, 2011 4:31 am
by gd77
!preg_match('/^[\+][0-9]{2,3}[\-][0-9]{1,2}[\-][0-9]{3}[\-][0-9]{3}$/i')

Still same problem... :banghead:

Re: preg_match problem

Posted: Sun Feb 27, 2011 7:11 am
by DigitalMind

Code: Select all

/^\+\d{3}-\d{2}-\d{3}-\d{3}$/

Re: preg_match problem

Posted: Sun Feb 27, 2011 8:30 am
by gd77
still same :S

Re: preg_match problem

Posted: Sun Feb 27, 2011 9:20 am
by DigitalMind
What are you trying to do?

Re: preg_match problem

Posted: Sun Feb 27, 2011 12:44 pm
by gd77
it's mentioned on top of the page :P :drunk:

Re: preg_match problem

Posted: Sun Feb 27, 2011 9:21 pm
by Jonah Bron
I don't know what you're doing, but this...

Code: Select all

preg_match('/^\+\d{3}-\d{2}-\d{3}-\d{3}$/', '+584-69-589-985');
...returns true. Maybe you should show us your code? Are you just trying to validate it, or actually extract those numbers?

Re: preg_match problem

Posted: Mon Feb 28, 2011 6:26 am
by gd77
as you see above, trying to validate a phone number or string matching +xxx-xx-xxx-xxx as mentioned the main reg...exp. works my main problem it does notwork with preg_match....

Re: preg_match problem

Posted: Mon Feb 28, 2011 9:11 am
by DigitalMind
it does