Checking for patterns and validating the user inputs using Regular Expression

Regular expressions is a powerful object of VBScript to use in any string matching and particularly in pattern matching. This is highly important to maintain data uniformity and prevents any malicious code or characters to enter to the system other than the required patterns.

If user inputs are not validated the attackers can use this to get entry inside the protected area and this is known as injection attack. You can read more on this security issues here and here.

For example we don't want any one to use any character inside the field specified for entering zip or pin code inside a form. Same way for a phone number we may allow hyphens (- ) and numbers but not characters. User id should contain only number and characters and it should be minimum 3 and maximum 8 char length. We can check one valid email address by checking the pattern used.

Regular Expression is a big subject and there are different ways to match patterns here. More details can be found at Microsoft MSDN home page and at regular expression tutorial

We need to first initiate the VBScript regular expression object and here is the code for that.

dim RExp : set RExp = new RegExp



We will see the use of this object in our examples for validating different inputs.
Let us start with some simple validations using regular expression.

Validating for user id & password: Here we will allow only characters and numbers within a minimum and maximum length

Validating Email address

Validating date entered by users

Validating zip code

Validating telephone number

Be the first to post comment on this article :

plus2net.com




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 your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer