Function FormatPhoneNumb ers(ByVal strInputPhoneNu mber As String) As String
'Strip off the ( , ) and -
Dim strPhoneNumber As String
strInputPhoneNu mber = strInputPhoneNu mber.Replace(" ", "")
strInputPhoneNu mber = strInputPhoneNu mber.Replace("( ", "")
strInputPhoneNu mber = strInputPhoneNu mber.Replace(") ", "")
strInputPhoneNu mber = strInputPhoneNu mber.Replace("-", "")
'Now format it
If strInputPhoneNu mber.Length >= 3 Then
strPhoneNumber = "(" & strInputPhoneNu mber.Substring( 0, 3) & ") "
If strInputPhoneNu mber.Length < 6 Then
strPhoneNumber = strPhoneNumber & strInputPhoneNu mber.Substring( 3,
strInputPhoneNu mber.Length - 3)
Else
strPhoneNumber = strPhoneNumber & strInputPhoneNu mber.Substring( 3,
3) & "-" & strInputPhoneNu mber.Substring( 6)
End If
End If
Return strPhoneNumber
End Function
--
Swanand Mokashi
Microsoft Certified Professional
http://www.swanandmokashi.com/
Home of the Stock Quotes, Quote of the day and Horoscope web services
"Eddy Soeparmin" <es********@cli entprofiles.com > wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
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
"Ray Dixon [MVP]" <ra*@NOSPAM.gre eble.com> wrote in message
news:uu******** ******@TK2MSFTN GP12.phx.gbl... Hi Eddy,
If you are validating input, you can use a RegularExpressi onValidator
and select U.S. Phone Number in the Regular Expression Editor (by clicking
the elipses in the ValidationExpre ssion box in the
RegularExpressi onValidator's Properties window).
--
Ray Dixon - Microsoft MVP
ra*@NOSPAM.gree ble.com
(remove NOSPAM. from my e-mail address for a direct reply)
"Eddy Soeparmin" <es********@cli entprofiles.com > wrote in message
news:uC******** ******@TK2MSFTN GP11.phx.gbl... Hi,
How do I apply phone format in a string field? for example (770)
123-1234. Please let me know.
Thanks.
Eddy