vb Validation using Regular Expression replacement

Function Clean(strData)
	Dim vRegEx  
	Set vRegEx = new RegExp
	vRegEx.IgnoreCase = True
	vRegEx.Global = True
	vRegEx.Pattern = "[^-a-zA-Z0-9-;,' ]"
	vRegEx.Pattern = "[^0-9]"
	'phone number
	vRegEx.Pattern = "[^0-9\(\)\-ext. ]"
	'email address
	vRegEx.Pattern = "[^-a-zA-Z0-9@.!$&*-=^`|~#%'+/?_{}]"
	'password (assuming only letters and numbers)
	vRegEx.Pattern = "[^a-zA-Z0-9]"
	strData = CStr(strData)
	Clean = vRegEx.Replace(strData,"")
	Set vRegEx = Nothing
End Function
Used for whitelisting characters accepted - by replacing invalid characters using Regular Expression. Note - you only need one of the vRegEx.Pattern lines (this merely displays several common expressions).

Updated: Saturday 2nd October 2010, 22:37am

There are 0 comments

Leave a comment of your own

Comments are currently closed.