preg_match problem
Moderator: General Moderators
preg_match problem
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.
$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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: preg_match problem
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}$/
/^[\+][0-9]{2,3}[\-][0-9]{1,2}[\-][0-9]{3}[\-][0-9]{3}$/
(#10850)
Re: preg_match problem
!preg_match('/^[\+][0-9]{2,3}[\-][0-9]{1,2}[\-][0-9]{3}[\-][0-9]{3}$/i')
Still same problem...
Still same problem...
- DigitalMind
- Forum Contributor
- Posts: 152
- Joined: Mon Sep 27, 2010 2:27 am
- Location: Ukraine, Kharkov
Re: preg_match problem
Code: Select all
/^\+\d{3}-\d{2}-\d{3}-\d{3}$/Re: preg_match problem
still same :S
- DigitalMind
- Forum Contributor
- Posts: 152
- Joined: Mon Sep 27, 2010 2:27 am
- Location: Ukraine, Kharkov
Re: preg_match problem
What are you trying to do?
Re: preg_match problem
it's mentioned on top of the page

- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: preg_match problem
I don't know what you're doing, but this...
...returns true. Maybe you should show us your code? Are you just trying to validate it, or actually extract those numbers?
Code: Select all
preg_match('/^\+\d{3}-\d{2}-\d{3}-\d{3}$/', '+584-69-589-985');Re: preg_match problem
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....
- DigitalMind
- Forum Contributor
- Posts: 152
- Joined: Mon Sep 27, 2010 2:27 am
- Location: Ukraine, Kharkov
Re: preg_match problem
it does