/    Sign up×
Community /Pin to ProfileBookmark

Regular Expression

HI

I am trying to write a regular expression that should match the following cases

  • 1. Should start with either + or 00

  • 2. After p#1, it should have numbers only and length between 11 – 16 chars

  • 3. Overall length including pt#1 and pt#2 should be minimum 12 chars and max 17 chars
  • Which means the following should be valid:
    +95215487511
    0041587695157

    My following expression does not work fine ?

    [code=php]
    <?php
    $reg =”/^[+|00]{1}[0-9]{12,16}$/”;
    $number = ‘065471852956’;
    $x = preg_match( $reg , $number);

    var_dump($x); // returns true
    [/code]

    Any help is appreciated

    Thanks

    to post a comment
    PHP

    6 Comments(s)

    Copy linkTweet thisAlerts:
    @phantom007authorJul 30.2013 — One more rule

  • 4. if there is + then it cannot be followed by zero, and if there are 00 then it cannot have + at beginning.
  • Copy linkTweet thisAlerts:
    @NoEffinWayJul 30.2013 — I think this should do it:
    [CODE]/^+{1}[1-9]{11,16}$|^00{1}[1-9]{11,16}$/[/CODE]

    These are your best friends:

    REGEX CheetSheet

    REGEX Tester
    Copy linkTweet thisAlerts:
    @iBeZiJul 30.2013 — This should work as an alternative to NoEffinWay's solution

    <i>
    </i>/^(?:+|00)[1-9][0-9]{10,15}$/
    Copy linkTweet thisAlerts:
    @phantom007authorJul 31.2013 — HI Thanks for the replies.


    NoEffinWay's solution does not seem to be working (for example +123456789012)

    iBeZi, ur regex works so far, will keep testing for more combinations and will update you.


    Thanks again

    cheers
    Copy linkTweet thisAlerts:
    @phantom007authorAug 19.2013 — Hi Again


    I am using the following regex:
    [CODE]/^(?:+|00)[1-9][0-9]{10,15}$/[/CODE]

    But it does not validate the following two numbers, any idea why?

    [CODE]005374152368
    +4865718575[/CODE]



    Thanks
    Copy linkTweet thisAlerts:
    @iBeZiAug 19.2013 — Hi Again


    I am using the following regex:
    [CODE]/^(?:+|00)[1-9][0-9]{10,15}$/[/CODE]

    But it does not validate the following two numbers, any idea why?

    [CODE]005374152368
    +4865718575[/CODE]



    Thanks[/QUOTE]


    The numbers aren't long enough (+ or 00 followed by a number in the range of 1-9 followed by 10-15 of any number).

    The first number is 00 followed by a number (5), followed by only 9 other numbers, same with the second number except starting with +
    ×

    Success!

    Help @phantom007 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...