SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regular expressions problem

    Hi all,

    I created a regex for matching mobile number ..

    $search = preg_match_all("~(\d{1,}\s?|\d?\s?\(\d{1,}\)|\d{1,}-)?\s{0,}\d{1,}[.\s]?/?[.\-]?[.\s\-\s]?\d{1,}[.\s]?\d{1,}[.\s]?[.\-]?[.\s\-\s]?\d{1,}~",$text,$matches);




    It works fine with most phone numbers, but sometimes it doesn't work ..
    This is a sample of a working number : + 2 010 5646024
    and this is a sample of a not working number : + 2 385 230 61
    I don't understand why the second number + 2 385 230 61 is not matched ...
    N.B When I add any integer to the second number , it works , eg + 2 385 230 611

    So how can I edit my regex to match the second number?

    Regards,

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    How do you define a mobile number for your country?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not important for that...
    But only I want to edit the code to match also this number + 2 385 230 611

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,203
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Why not just keep it simpler, allowing a certain number of digits (say 12 or so), + and spaces?

  5. #5
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How to do so ?
    I'm pretty new to using regular expressions

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,203
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by darroosh View Post
    I'm pretty new to using regular expressions
    Me too.

    Perhaps something like this? (Replace $phone with your own variable.)

    PHP Code:
    preg_match("/^[0-9\s\+]{8,16}$/"$phone


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •