Avatar of ipjyo
ipjyo
Flag for United States of America

asked on 

how do we stop special characters while entering into text area?

I have a text area which should accept only alphanumeric characters.
Currently I have a validation function (as shown in the attached) which returns either true or false.
Based on the return value, it will print a message. (Valid or Invalid)
Now the requirement is, Instead of validating the entered characters I should stop them while entering them. I guess I need to use regular expressions but no idea how to implement this.
Could anybody please guide me if you have a solution.

Thanks!
Function IsAlphaNumeric(stritem) 
		dim regExp, match, i, spec
		For i = 1 to Len(stritem)
			spec = Mid(stritem, i, 1)
			Set regExp = New RegExp
			regExp.Global = True
			regExp.IgnoreCase = True
			regExp.Pattern = "[A-Z]|[a-z]|[0-9]"
			set match = regExp.Execute(spec)
		  	If match.count = 0 then
				IsAlphaNumeric = False
				Exit Function
			End If
			Set regExp = Nothing
		Next
		IsAlphaNumeric = True
	End Function

Open in new window

Regular ExpressionsASP

Avatar of undefined
Last Comment
ipjyo

8/22/2022 - Mon