Checking user id and password for only character and numbers using Regular Expression
We can check the entered user id of any user within a web form by using Regular Expression. This is to prevent user or attacker to use other characters and codes in the input field. Here we will check for special characters but checking for special characters and then for length is a bit lengthy process so we will check for existence of characters, numbers and number of characters used.
Here is the complete code. The output of this is true or false based on the result of validation.
Dim userid
dim RExp : set RExp = new RegExp
with RExp
.Pattern = "^[a-zA-Z0-9]{3,8}$"
.IgnoreCase = True
.Global = True
end with
userid= "a234f678"
Response.Write RExp.test(userid)
Here only characters lower or upper case along with numbers is allowed. The length of the string has to be minimum 3 and maximum 8 char length.
Here is some different values of the string ( userid ) for which the validation will pass and output will be True.