VB icon

ASP Format Function

Email
Submitted on: 1/6/2015 4:15:00 PM
By: Brian Reeves (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: ASP (Active Server Pages)
Views: 3040
 
     This function operates similarly to the VB Format function with one big exception. The "#" character is used to represent any single character. You can trim all non alphanumeric characters out and reformat them to stay consistant. Usefull for credit cards, zipcodes, phone numbers, etc...
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
' for :ASP Format Function
'**************************************
Open Source
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: ASP Format Function
' Description:This function operates similarly to the VB Format function with one big exception. The "#" character is used to represent any single character. You can trim all non alphanumeric characters out and reformat them to stay consistant.
Usefull for credit cards, zipcodes, phone numbers, etc...
' By: Brian Reeves (from psc cd)
'
' Assumes:Format("1234567890123", "(###) ###-#### x######") would return "(123) 456-7890 x123"
Format("4111111111111111", "####-####-####-####")
would return "4111-1111-1111-1111"
'**************************************

'******
'**		Formats a string to include standard sets.
'**
'**		Example:	Format("1234567890", "(###) ###-####")
'**			Result =	(123) 456-7890
'**		Modified 01/09/03 to allow extended format mask that will
'**			not return extra ###'s brian reeves
'******
Public Function Format(sValue, sMask)
	Dim iPlaceHolder
	Dim sTempValue
	Dim sResult
	
	sTempValue = CStr(sValue)
	sResult = sMask
	Do Until InStr(sResult, "#") = 0
		iPlaceHolder = InStr(sResult, "#")
		sResult = Replace(sResult, "#", Left(sTempValue, 1), 1, 1)
		sTempValue = Mid(sTempValue, 2)
		If Len(sTempValue) = 0 Then sResult = Left(sResult, iPlaceHolder)
	Loop
	Format = sResult
End Function


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.