vb Validation using Regular Expression replacement

Function Clean(strData)
	Dim vRegEx  
	Set vRegEx = new RegExp
	vRegEx.IgnoreCase = True
	vRegEx.Global = True
	
	'alphanumeric
	vRegEx.Pattern = "[^-a-zA-Z0-9-;,' ]"
	
	'numeric
	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, 07:33am

There are 0 comments

Leave a comment of your own

Comments are currently closed.