MkPhoneNum Function:

The MkPhoneNum Function creates a formatted phone number from either long or string input. The input phone number should follow one of the following formats ( where x is alphanumeric ): MkPhoneNum will attempt to remove all spaces and number delimiters ( "(" , ")" , "-" ) from the input string before checking it's length for the proper formatting. MkPhoneNum will return Null if the resulting string cannot be recognized as a valid US phone number otherwise MkPhoneNum returns a US formatted phone number. MkPhoneNum doesn't recognize number formats that do not follow US Telephone standards.

Syntax:
string = MkPhoneNum( phonenumber )
Example Usage:
<%
response.write MkPhoneNum( 5551452 )
 ' returns "555-1452"
response.write MkPhoneNum( 8005551452 )
 ' returns "(800) 555-1452"
response.write MkPhoneNum( 18005551452 )
 ' returns "1 (800) 555-1452"
response.write MkPhoneNum( "JL51452" )
 ' returns "JL5-1452"
response.write MkPhoneNum( "1-800-CALL-BIL" )
 ' returns "1 (800) CALL-BIL"
response.write MkPhoneNum( "1 800 CALL BIL" )
 ' returns "1 (800) CALL-BIL"
response.write MkPhoneNum( "33-22-11-00" )
 ' returns NULL   - incorrect length after the "-" char is stripped...
%>
ASP Source Code:
<%
Private Function MkPhoneNum(byVal number)
	Dim tmp
	number = CStr( number )
	number = Trim( number )
	number = Replace( number, " ", "" )	
	number = Replace( number, "-", "" )
	number = Replace( number, "(", "" )
	number = Replace( number, ")", "" )
	Select Case Len( number )
		Case 7
			tmp = tmp & Mid( number, 1, 3 ) & "-"
			tmp = tmp & Mid( number, 4, 4 )
		Case 10
			tmp = tmp & "(" & Mid( number, 1, 3 ) & ") "
			tmp = tmp & Mid( number, 4, 3 ) & "-"
			tmp = tmp & Mid( number, 7, 4 )
		Case 11
			tmp = tmp & Mid( number, 1, 1 ) & " "
			tmp = tmp & "(" & Mid( number, 2, 3 ) & ") "
			tmp = tmp & Mid( number, 5, 3 ) & "-"
			tmp = tmp & Mid( number, 8, 4 )
		Case Else
			MkPhoneNum = Null
			Exit Function
	End Select
	MkPhoneNum = tmp
End Function
%>