Formatting phone number

1. Senior Member
Join Date
Dec 1969
Posts
196

## Formatting phone number

Hi,<BR><BR>I have a phone number field where user can enter phone number in so many ways.<BR>For example, somebody can enter as (123)456-7890 or 34567, or 234-5678 or 1234567.<BR>I have to put them in array and display correctly.<BR><BR>(123)456-7890 and 234-5678 === displays same <BR>34567====== should display like 3-4567 and<BR>1234567=====should display like 123-4567.<BR><BR>I know the logic but failed to do the code. Can somebody give me little idea. <BR>THANKS IN ADVANCE.

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: Formatting phone number

Check out Left(), Mid(), Right(), and Len(). Maybe even InStr().

3. Senior Member
Join Date
Dec 1969
Posts
196

## RE: Formatting phone number

4. Junior Member
Join Date
Dec 1969
Posts
15

## RE: Formatting phone number

you can do something like<BR>x = replace(x,"(","")<BR>x = replace(x,")","")<BR>x = replace(x,"-","")<BR>for ()- and any other characters...then<BR><BR>if len(x)=5 then<BR> phonenumber = left(x,1) & "-" & right(x,4)<BR>elseif len(x) = 7 then<BR> phonenumber = left(x,3) & "-" & right(x,4)<BR>etc,etc,etc<BR>end if<BR><BR>JS

5. Senior Member
Join Date
Dec 1969
Posts
196

## Thanks

I got it.

6. Senior Member
Join Date
Dec 1969
Posts
2,493

## RE: Thanks

I use 3 fields<BR>&#060;input type="phone" maxlength="3" size="4"&#062;-<BR>&#060;input type="phone" maxlength="3" size="4"&#062;-<BR>&#060;input type="phone" maxlength="4" size="5"&#062;<BR><BR>then on the response page<BR><BR>varPhone=Replace(Request(phone"),", ","-")<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
2,493

## oops!

Thats input type="text name="phone"

8. Senior Member
Join Date
Dec 1969
Posts
196

## Thanks

Steve. This is great way to display the phone field. But I have to give them an option where they can just write 5 numbers because it is inside the campus. Usually phone numbers are 5 numbers(23456). <BR>Thanks a lot.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•