README.md

December 5, 2022 ยท View on GitHub

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...

More Info

Format("1234567890123", "(###) ###-#### x######") would return "(123) 456-7890 x123"

Format("4111111111111111", "####-####-####-####")

would return "4111-1111-1111-1111"

Submitted On
ByBrian Reeves
LevelIntermediate
User Rating5.0 (15 globes from 3 users)
CompatibilityASP (Active Server Pages)
CategoryValidation/ Processing
WorldASP / VbScript
Archive File

API Declarations

Open Source

Source Code

'******
'**		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