Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 560885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:23:29+00:00 2026-05-13T12:23:29+00:00

There has got to be an easier way to do this. I am trying

  • 0

There has got to be an easier way to do this.

I am trying to wirte a function for a Phone number class called “import phone number”. It should take any string with 10 digits in it somewhere (and allow for an extension), and import them into it’s own properties: AreaCode, Prefix, Suffix, and Extension (aaa-ppp-ssss-xxxx…).

I check the input with a regex to make sure it’s valid, now i want to tokenize those pieces into their respective properties. What I have looks like this (incomplete):

Public Sub ImportPhoneNumber(ByVal anyNumber As String)
    'phone number is 10-digits long, e.g.: 012-345-6789
    Dim reg_exp_10 As New Regex("^((\D*)\d(\D*)){9}((\D*)\d){1}(((x|ext){1}(\d)+)?|\D*)$", RegexOptions.IgnoreCase)

    If reg_exp_10.IsMatch(anyNumber) Then
        Dim areacode As String = HRITS.Constants.DEFAULT_STRING_VALUE
        Dim prefix As String = HRITS.Constants.DEFAULT_STRING_VALUE
        Dim suffix As String = HRITS.Constants.DEFAULT_STRING_VALUE
        Dim loadExtension As Boolean = False
        Dim count As Integer = 0
        'for each char in anynumber, is it a number? concatenate it onto holder number
        For Each i As Char In anyNumber
            'first 3 hits, load areacode
            If count < 3 Then
                If Char.IsDigit(i) Then
                    areacode = String.Concat(areacode, i)
                    count = count + 1
                End If
            End If
            'second 3 hits, load prefix
            If count >= 3 AndAlso count < 6 Then
                If Char.IsDigit(i) Then
                    prefix = String.Concat(prefix, i)
                    count = count + 1
                End If
            End If
            'third 4 hits, load suffix
            If count >= 6 AndAlso count < 10 Then
                If Char.IsDigit(i) Then
                    suffix = String.Concat(suffix, i)
                    count = count + 1
                End If
            End If

            If count >= 10 Then
                If i.ToString = "x" Then
                    loadExtension = True
                ElseIf i.ToString = "e" Then

                End If
            End If

        Next
    Else
        Throw New Exception(ErrorMessages.PhoneNumber.INVALID_NUMBER)
    End If

End Sub

any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:23:29+00:00Added an answer on May 13, 2026 at 12:23 pm

    Here we go:

    /(\d{3})\D*(\d{3})\D*(\d{4})\D*(\d*)/
    

    Area Code, Prefix, Suffix, Extension in capture groups 1 through 4 respectively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There has GOT to be a simple way to programmatically render HTML into a
I've got following problem: (c#) There is some class (IRC bot), which has method,
There has to be a better way of writing the js in my function....
Okay, I really know this has GOT to be the long way around doing
In Perl, is there any way to tell which .pl script has initialized this
I've got a JTextArea which has the following text Text1 Text2 Text3. Is there
If a page has both JQuery and Prototype then I got conflict. There is
Hey there! I'm doing this project and right now I'm trying to: create some
This is how far I got: <head> <script type=text/javascript> function showonlyone(thechosenone) { var article
There has been a lot of talk around iPad-Apps / Approval / Store-related Questions.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.