SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot dizyn's Avatar
    Join Date
    Apr 2006
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    phone numer validation

    i want to validate phone number like:

    +92.3335240141

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code Javascript:
    var phonenumber = '+92.3335240141';
    if (/\+\d{2}\.\d{10}/.test(phonenumber)) {
     // do stuff
    }
    Completely inflexible - doesn't allow spaces, omission of plus sign or omission of dot.

  3. #3
    SitePoint Zealot dizyn's Avatar
    Join Date
    Apr 2006
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what is .test ???
    can you please explain test

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It performs a matching test regular between the regular expression pattern (stuff before .) and the string in question (phonenumber).

    See this: http://developer.mozilla.org/en/docs...ts:RegExp:test

  5. #5
    Non-Member
    Join Date
    Aug 2006
    Location
    Kansas City
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would reccomend something like the following....

    var emailToMatch = "+92.3335240141";
    var RegToMatch = /\+\d{2}\.\d{10}/;

    if(RegToMatch.test(emailToMatch))
    {
    //Execute Code Here
    }

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That is practically identical to what I posted above.


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
  •