Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
Formating a phone number
Old 11-18-2004, 10:31 AM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
Instead of trying to write code that deals with messy data... is it possible for you to clean the data and make it more standardized?
Anacrusis is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-18-2004, 10:38 AM
netcrawler's Avatar
Average Talker

Posts: 27
Location: QC, Canada
Trades: 0
Impossible i'm not in charge of that database and it gets replicated daily with new data that is being added to it on a daily basis. The data is being added by hundreds of people weekly and there is no error checking on that database so making it impossible for me to adjust and make it right. Sorry but I can't make it standerized it's out of my hands.
netcrawler is offline
Reply With Quote
View Public Profile
 
Old 11-18-2004, 10:42 AM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
Ok, I'm working on getting the function to work on all those possiblities. But if a new possibility pops up that's not coded for it will break. There really should be error checking on the data entry side as this is not really the best place to do it as you can see.
Anacrusis is offline
Reply With Quote
View Public Profile
 
Old 11-18-2004, 10:47 AM
netcrawler's Avatar
Average Talker

Posts: 27
Location: QC, Canada
Trades: 0
I understand and I have told them that but they refused to re-code it due that it's been in place for some years now and they don't have the time to do it.. well they will have to deal with the other errors that will show up..then probably they will decide to do something??
netcrawler is offline
Reply With Quote
View Public Profile
 
Old 11-18-2004, 11:56 AM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
Ok, here we go. The function has gotten quite a bit more comlicated. I've tested it pretty well and it will format almost any number you throw at it. Try it out and let me know if you have any trouble.
Code:
Function FormatPhoneNumber(strNumber)
    dim ext
    dim tmp_str
    dim x
    
    tmp_str = lcase(strReverse(strNumber))
    for x = 1 to len(tmp_str)
        if not isnumeric(mid(tmp_str, x, 1)) then
            'found a possible ext, let's pull it out.
            ext = strReverse(left(tmp_str, x -1))
            strNumber = strReverse(right(tmp_str, len(tmp_str) - x))
            exit for
        end if
    next 'x
    
    'lets remove all existing formating
    'We want the number to end up looking like this: 1234567890
    tmp_str = ""
    for x = 1 to len(strNumber)
        if isnumeric(mid(strNumber, x, 1)) then
            tmp_str = tmp_str & mid(strNumber, x, 1)
        end if
    next 'x
    strNumber = tmp_str

    'if there is 11 digits and the first digit is 1 then
    if len(strNumber) = 11 and left(strNumber, 1) = "1" then
        'grab the last 10 characters
        strNumber = Right(strNumber, 10)
    elseif len(strNumber) <> 10 then 
        if len(strNumber) + len(ext) <> 10 then
            FormatPhoneNumber = ""
            exit function
        else
            strNumber = strNumber & ext
            ext = ""
        end if
    end if  

    if len(ext) > 0 then ext = "Ext: " & ext

    'reformat the number
    strNumber = "(" & Left(strNumber, 3) & ") " & Mid(strNumber, 4, 3) & "-" & Right(strNumber, 4)
    
    'tack on an extension if there is one:
    if len(ext) > 0 then
        strNumber = strNumber & " " & ext
    end if
        
    FormatPhoneNumber = strNumber

End Function
Anacrusis is offline
Reply With Quote
View Public Profile
 
Old 11-18-2004, 12:37 PM
netcrawler's Avatar
Average Talker

Posts: 27
Location: QC, Canada
Trades: 0
Hey buddy I give you a 5***** rating you rock!! It works nicely so far thanks a bunch you really helped me out. I hope one day to be as good as you so that I could help out big time the people in need of scripting.

Again Thanks.
netcrawler is offline
Reply With Quote
View Public Profile
 
Old 11-18-2004, 01:07 PM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
Glad it's working for you
Anacrusis is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Formating a phone number

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29159 seconds with 11 queries