SQL PHP HTML ASP JavaScript articles and free scripts to download

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.

We can imitate the regular expression object of VBScript like this.

dim RExp : set RExp = new RegExp

By using this object we can check any string.

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.

A234f678, a23, a2345f, a2345f6

It will fail or return False for these values

A2, a2345f6789, a23*5,a234f5/6


Google+

Further readings
Introduction to Regular Expression for validating user input
Validating userid and password by using regular expression for user entered data
Validating Email address by using regular expression
Form Handling in ASP, Get and Post methods
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer