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. Visual Basic
  4. Help with code for telephone validator

Help with code for telephone validator

Scheduled Pinned Locked Moved Visual Basic
help
28 Posts 7 Posters 2 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.
  • 1 12String

    So I should leave the Public Sub CheckInput() as is and delete the above msgBoxes? any suggestions on what to put in thier place LOL.

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #17

    12String wrote:

    any suggestions on what to put in thier place LOL.

    Exactly what I've suggested already - you can split the strings by the -, and then check the rest is numbers of the right length, or use a regex. Christian Graus - Microsoft MVP - C++

    1 1 Reply Last reply
    0
    • C Christian Graus

      12String wrote:

      any suggestions on what to put in thier place LOL.

      Exactly what I've suggested already - you can split the strings by the -, and then check the rest is numbers of the right length, or use a regex. Christian Graus - Microsoft MVP - C++

      1 Offline
      1 Offline
      12String
      wrote on last edited by
      #18

      The problem is the how. I do not know how to code it. Exactly how would you code it. I cannot find any examples or close to examples in this text I have it is most frustrating.

      C 1 Reply Last reply
      0
      • 1 12String

        The problem is the how. I do not know how to code it. Exactly how would you code it. I cannot find any examples or close to examples in this text I have it is most frustrating.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #19

        The regex I provided will work with Regex.IsMatch ( from memory ), otherwise I've given you the syntax for the split function, and said that you need to use Double.TryParse to see if they are numnbers. I'm reluctant to do much more, that should be enough for you to find out the rest, and as this is homework, the point is learning, not just doing. Christian Graus - Microsoft MVP - C++

        1 1 Reply Last reply
        0
        • C Christian Graus

          The regex I provided will work with Regex.IsMatch ( from memory ), otherwise I've given you the syntax for the split function, and said that you need to use Double.TryParse to see if they are numnbers. I'm reluctant to do much more, that should be enough for you to find out the rest, and as this is homework, the point is learning, not just doing. Christian Graus - Microsoft MVP - C++

          1 Offline
          1 Offline
          12String
          wrote on last edited by
          #20

          Herein lies another problem, when I enter the string()strings=string.split("-") VB gives me a syntax error stating that 'String is a class type, and so is not valid. Also Name 'TheString'is not declared. UFFFFF! You see my frustration. LOL

          C 1 Reply Last reply
          0
          • 1 12String

            Herein lies another problem, when I enter the string()strings=string.split("-") VB gives me a syntax error stating that 'String is a class type, and so is not valid. Also Name 'TheString'is not declared. UFFFFF! You see my frustration. LOL

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #21

            12String wrote:

            You see my frustration. LOL

            Yes, the problem is that you're looking for a cut and paste solution instead of thinking about it. string.split is my way of showing you where this function lives myString.split obviously requires you to replace myString with the name of the variable that holds the string in your program. Christian Graus - Microsoft MVP - C++

            S 1 Reply Last reply
            0
            • C Christian Graus

              12String wrote:

              You see my frustration. LOL

              Yes, the problem is that you're looking for a cut and paste solution instead of thinking about it. string.split is my way of showing you where this function lives myString.split obviously requires you to replace myString with the name of the variable that holds the string in your program. Christian Graus - Microsoft MVP - C++

              S Offline
              S Offline
              Steve Pullan
              wrote on last edited by
              #22

              Christian, you deserve some sort of an award :-) You are certainly blessed with above average patience! ...Steve

              C 1 Reply Last reply
              0
              • S Steve Pullan

                Christian, you deserve some sort of an award :-) You are certainly blessed with above average patience! ...Steve

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #23

                I regard it as a challenge at times to lead people to their required solution. It would be easy just to give him the code, but that's not really helping him, is it ? Having aspirations to project management, I need to work on my communication skills anyhow :-) Christian Graus - Microsoft MVP - C++

                D 1 Reply Last reply
                0
                • 1 12String

                  Can someone out there give a fellow a helping hand. I am desparately trying to code for a telephone validator. My form1 has only two objects, a textbox and a button. Validate a phonenumber 999-999-9999 Where I am running into a snag is how and where do I create the substrings for the areacode, prefix, and phonenumber plus incorporating the "-" in char positions (3,1) and (7,1) Can someone give me some assistance or better yet help me code the whole tamole. LOL. 12String 12String

                  S Offline
                  S Offline
                  seee sharp
                  wrote on last edited by
                  #24

                  Just a thought, what if we create a custom textbox which allow you to type only numbers and inserts "-" at proper places automaitcally - ashish

                  1 1 Reply Last reply
                  0
                  • S seee sharp

                    Just a thought, what if we create a custom textbox which allow you to type only numbers and inserts "-" at proper places automaitcally - ashish

                    1 Offline
                    1 Offline
                    12String
                    wrote on last edited by
                    #25

                    How would we go about doing that?

                    1 Reply Last reply
                    0
                    • C Christian Graus

                      I regard it as a challenge at times to lead people to their required solution. It would be easy just to give him the code, but that's not really helping him, is it ? Having aspirations to project management, I need to work on my communication skills anyhow :-) Christian Graus - Microsoft MVP - C++

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #26

                      Christian Graus wrote:

                      It would be easy just to give him the code, but that's not really helping him, is it ?

                      Bravo! One of the few who thinks it's better to learn by doing (and screwing it up!) than by having it spoon fed to you! To offer a different answer to his problem though... I've always done one of two things. Either used a Masked Edit Box or (more directly to his problem) just let the user type whatever they wanted into the box. Then in the validation or submit process, strip out everything that wasn't a number to create a string of numbers, measure the length for completeness, then put the dashes and parentheses (if needed) back in where they're supposed to go. Walla! Instant phone number that can be re-edited at any time, if needed. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                      C 1 Reply Last reply
                      0
                      • D Dave Kreskowiak

                        Christian Graus wrote:

                        It would be easy just to give him the code, but that's not really helping him, is it ?

                        Bravo! One of the few who thinks it's better to learn by doing (and screwing it up!) than by having it spoon fed to you! To offer a different answer to his problem though... I've always done one of two things. Either used a Masked Edit Box or (more directly to his problem) just let the user type whatever they wanted into the box. Then in the validation or submit process, strip out everything that wasn't a number to create a string of numbers, measure the length for completeness, then put the dashes and parentheses (if needed) back in where they're supposed to go. Walla! Instant phone number that can be re-edited at any time, if needed. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                        C Offline
                        C Offline
                        Christian Graus
                        wrote on last edited by
                        #27

                        Dave Kreskowiak wrote:

                        Masked Edit Box

                        Yeah, the easiest way to validate is to only let the user type in something that is valid :-) I can't recall if it was apparent if this was a web or windows UI though. I know it can be done with a web UI, but I tend to shun Jscript as I fear browser issues. Christian Graus - Microsoft MVP - C++

                        1 Reply Last reply
                        0
                        • 1 12String

                          What I need to do is verify the first three 999 the first "-" second 999 second "-" and last four 9999. In the frmMain I have a textbox and a button. when the user enters a phone number 999-999-9999 the program will display one of the following messages: "You must enter a numeric telephone number starting with the area code." "You must enter a "-" after the area code." "YOu must enter a "-" after the prefix." "Invalid area code, please try again." "Invalid prefix, please try again." "Phone number is valid." My problem is I have set the char to 12 in the properties for textbox1 and I need to create substrings for area code, prefix, phonenumber, and incorporate the two dashes "-" Can you help me!

                          D Offline
                          D Offline
                          DA_Loring
                          wrote on last edited by
                          #28

                          What about a masked edit control with the mask set to "999-999-9999"??

                          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