PDA

View Full Version : Telephone number formating


netcrawler
11-15-2004, 03:09 PM
Hi I need help with a telephone number script formater, I have tried a couple of ways but had no luck to achive what i am trying to do here is what I am trying to do:

I have a database with telephone number entries but the problem is that they do not have all the same format the format i want them to be is: (111)111-1111.

In the database the person(s) entering the info entered all kind of formats like 111-111-1111, (111)11111111, 111 111-1111 and so forth.

Is there a simple method that would read in all digits in a seperate string and strip all non numeric values to have the following 1111111111 then for example:

if in=7
write number in this format and add "-" 111-1111

if in > 7
write write number in this format and add "( )" and "-" to become (111)111-1111.

and so forth..

I dont know if im clear in what i am trying to achive but hope it helps to help me.

Thanks..

fractalvibes
11-15-2004, 03:25 PM
Do a replace of all "-", parentheses, etc. and then reformat as you wish.

fv

netcrawler
11-15-2004, 03:29 PM
ok but can you show me a asp example cause im kind of new and dont know all the scripts by heart.. it would be greatly apreciated to have a simple example for just one telephone number then i could work the code for the rest of the formats.

Ex: give me a working example for this type of format

111-111-1111 to have it as (111) 111-1111

thanks and hope its not to demanding ... im just new and need lots of help.

fractalvibes
11-15-2004, 03:57 PM
start by doing something like:
[code]
phoneNumber = replace(phoneNumber, "-","")
phoneNumber = replace(phoneNumber,"(","")
phoneNumber = replace(phoneNumber,")","")
AC = Left(phoneNumber,3)
Prefix = Mid(phoneNumber,4,3)
Suffix = Right(phoneNumber,4)
[\code]

then concatenate the pieces together as you wish.
NewPhone = "(" & AC & ")" & " " & Prefix & "-" & Suffix

fv