Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2008
    Posts
    64
    Thanks
    25
    Thanked 0 Times in 0 Posts

    RegExp phone number help

    hey guys, using regxp
    and i have a phone number form which needs to have +33 0 at the start and then 5 numbers

    i have this so far
    Code:
    (/^\+33\s 0(\d{5}$)/);
    can someone help?

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by johnish View Post
    hey guys, using regxp
    and i have a phone number form which needs to have +33 0 at the start and then 5 numbers

    i have this so far
    Code:
    (/^\+33\s 0(\d{5}$)/);
    can someone help?
    see this doc about phone numbers:

    http://www.itu.int/rec/T-REC-E.123/en

    I use this with onblur, to reformat the phone number. The val value is the string from input, you can get it for example with document.getElementById('phid').value or something similar. With returned value must fill the input.
    Code:
    function phone_normalize_e123(val){
      var pn = (val ? (val.replace(/[^\(\)\+\d]/g,'')) : '');
      if(/^\+/.test(pn)){
        return pn.replace(/[\+\(\)]/g,'').replace(/^(\d{2})(\d{2})(\d{3})(\d{4})$/,"+$1 $2 $3 $4");
      }
      if(/^\(/.test(pn)){
        return pn.replace(/[\+\(\)]/g,'').replace(/^(\d{3})(\d{3})(\d{4})$/,"($1) $2 $3");
      }
      return pn;
    }
    this validate val to be valid formated. Same explanation about val, it return true or false.
    Code:
    function check_phone_e123(val){
      return (val ? (/^\(\d{3}\)\s\d{3}\s\d{4}$/.test(val) ||
                     /^\+\d{2}\s\d{2}\s\d{3}\s\d{4}$/.test(val)) : false);
    }
    work only toghater, that to make the check_phone_e123 regex simpler.

    best regards

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,011
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by johnish View Post
    hey guys, using regxp
    and i have a phone number form which needs to have +33 0 at the start and then 5 numbers

    i have this so far
    Code:
    (/^\+33\s 0(\d{5}$)/);
    can someone help?
    What was wrong with your regex was the space befoe the 0. Should be:-

    Code:
    if(/(^\+33\s0\d{5}$)/.test(lstr.value)) {


  •  

    Posting Permissions

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