Phone Format (770) 123-1234

  • Thread starter Thread starter Eddy Soeparmin
  • Start date Start date
E

Eddy Soeparmin

Hi,

How do I apply phone format in a string field? for example (770) 123-1234.
Please let me know.

Thanks.

Eddy
 
Hi Eddy,

If you are validating input, you can use a RegularExpressionValidator and
select U.S. Phone Number in the Regular Expression Editor (by clicking the
elipses in the ValidationExpression box in the RegularExpressionValidator's
Properties window).
 
you'd have to use javascript to do this
Eddy Soeparmin said:
Hi Ray,

No, this is not at validation. It's for display. For example, I just
retrieved data from database and would like to display phone number in (123)
123-1234 format within a datagrid.

Eddy
 
Function FormatPhoneNumbers(ByVal strInputPhoneNumber As String) As String

'Strip off the ( , ) and -

Dim strPhoneNumber As String

strInputPhoneNumber = strInputPhoneNumber.Replace(" ", "")

strInputPhoneNumber = strInputPhoneNumber.Replace("(", "")

strInputPhoneNumber = strInputPhoneNumber.Replace(")", "")

strInputPhoneNumber = strInputPhoneNumber.Replace("-", "")

'Now format it

If strInputPhoneNumber.Length >= 3 Then

strPhoneNumber = "(" & strInputPhoneNumber.Substring(0, 3) & ") "

If strInputPhoneNumber.Length < 6 Then

strPhoneNumber = strPhoneNumber & strInputPhoneNumber.Substring(3,
strInputPhoneNumber.Length - 3)

Else

strPhoneNumber = strPhoneNumber & strInputPhoneNumber.Substring(3,
3) & "-" & strInputPhoneNumber.Substring(6)

End If

End If

Return strPhoneNumber





End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

formatting a phone number in a string 2
format phone numbers with an 800 2
formula to format 5
Remove text 5
Sorting Data 3
Formula and Formating Help 5
Data Sorting 1
How to find similar records? 8

Back
Top