Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. south african phone number validation

south african phone number validation

Scheduled Pinned Locked Moved C#
regexhelptutorialquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Morgs Morgan
    wrote on last edited by
    #1

    hi guys, Iam try to validate a south african phone number. I have tried this but it won't work:

    Regex rx = new Regex(((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7}));

    here is an example of numbers I would want to validate: - 0 74 3720198 - 0 72 3720198 - 27 74 3720198 - +27 74 3720198 Please help me if Iam making a mistake somewhere I have tried google but no help so far... Thanks, Morgan Freeman

    K OriginalGriffO O 3 Replies Last reply
    0
    • M Morgs Morgan

      hi guys, Iam try to validate a south african phone number. I have tried this but it won't work:

      Regex rx = new Regex(((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7}));

      here is an example of numbers I would want to validate: - 0 74 3720198 - 0 72 3720198 - 27 74 3720198 - +27 74 3720198 Please help me if Iam making a mistake somewhere I have tried google but no help so far... Thanks, Morgan Freeman

      K Offline
      K Offline
      Keith Barrow
      wrote on last edited by
      #2

      I'm afraid I can't help much with the regex for SA numbers, as I don't know the ins-and-outs of how they are comprised. (Someone else here might be able to help directly), but this [free] tool will speed up validation: http://www.radsoftware.com.au/regexdesigner/[^] Also this could be of some help: http://regexlib.com/Search.aspx?k=south+africa[^]

      Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter. Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.

      M 1 Reply Last reply
      0
      • M Morgs Morgan

        hi guys, Iam try to validate a south african phone number. I have tried this but it won't work:

        Regex rx = new Regex(((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7}));

        here is an example of numbers I would want to validate: - 0 74 3720198 - 0 72 3720198 - 27 74 3720198 - +27 74 3720198 Please help me if Iam making a mistake somewhere I have tried google but no help so far... Thanks, Morgan Freeman

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Your first problem is the spaces between the digits. Try something a bit simpler, and work your way up to the full expression: "((0\s)|(27\s))(?<AreaCode>[0-9]{2})(?<LocalNumber>\s[0-9]{7})" Feed this into Expresso[^] - examines and generates Regular expressions. It's free, and it really helps!

        You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        M 2 Replies Last reply
        0
        • M Morgs Morgan

          hi guys, Iam try to validate a south african phone number. I have tried this but it won't work:

          Regex rx = new Regex(((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7}));

          here is an example of numbers I would want to validate: - 0 74 3720198 - 0 72 3720198 - 27 74 3720198 - +27 74 3720198 Please help me if Iam making a mistake somewhere I have tried google but no help so far... Thanks, Morgan Freeman

          O Offline
          O Offline
          O Phil
          wrote on last edited by
          #4

          Hi, First of all, regular expression must be defined using a string, so you have to instanciate it that way :

          Regex rx = new Regex("((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7})");

          Moreover, as OriginalGriff told you, consider using a tool like Expresso to build and test your regular expressions. Regards.

          M 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Your first problem is the spaces between the digits. Try something a bit simpler, and work your way up to the full expression: "((0\s)|(27\s))(?<AreaCode>[0-9]{2})(?<LocalNumber>\s[0-9]{7})" Feed this into Expresso[^] - examines and generates Regular expressions. It's free, and it really helps!

            You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

            M Offline
            M Offline
            Morgs Morgan
            wrote on last edited by
            #5

            OriginalGriff wrote:

            Your first problem is the spaces between the digits

            thanks man, with spaces I was just trying to indicate where the full number is branched or divided I will try your idea and thanks alot Morg

            1 Reply Last reply
            0
            • K Keith Barrow

              I'm afraid I can't help much with the regex for SA numbers, as I don't know the ins-and-outs of how they are comprised. (Someone else here might be able to help directly), but this [free] tool will speed up validation: http://www.radsoftware.com.au/regexdesigner/[^] Also this could be of some help: http://regexlib.com/Search.aspx?k=south+africa[^]

              Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter. Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.

              M Offline
              M Offline
              Morgs Morgan
              wrote on last edited by
              #6

              thanks man I will try your links and thanks alot Morg

              1 Reply Last reply
              0
              • O O Phil

                Hi, First of all, regular expression must be defined using a string, so you have to instanciate it that way :

                Regex rx = new Regex("((?:\\+27|27)|0)(72|82|73|83|74|84)(\\d{7})");

                Moreover, as OriginalGriff told you, consider using a tool like Expresso to build and test your regular expressions. Regards.

                M Offline
                M Offline
                Morgs Morgan
                wrote on last edited by
                #7

                Thanks man

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  Your first problem is the spaces between the digits. Try something a bit simpler, and work your way up to the full expression: "((0\s)|(27\s))(?<AreaCode>[0-9]{2})(?<LocalNumber>\s[0-9]{7})" Feed this into Expresso[^] - examines and generates Regular expressions. It's free, and it really helps!

                  You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

                  M Offline
                  M Offline
                  Morgs Morgan
                  wrote on last edited by
                  #8

                  hey hey thanks man that program is so cool, I managed to figure out what was wrong, the right expr: Regex rx = new Regex("((?:\+27|27)|0)(72|82|73|83|74|84)(\d{7})"); Great one!

                  OriginalGriffO 1 Reply Last reply
                  0
                  • M Morgs Morgan

                    hey hey thanks man that program is so cool, I managed to figure out what was wrong, the right expr: Regex rx = new Regex("((?:\+27|27)|0)(72|82|73|83|74|84)(\d{7})"); Great one!

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #9

                    I wish I'd written it! :laugh:

                    You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups