The VBScript RegExp object can test whether a string matches a required pattern. In Classic ASP this is useful for validating the shape of values such as user IDs or email addresses before further processing.
Pattern validation is only one layer of security. It does not replace prepared/parameterized database commands, output encoding, authorization checks, or business-rule validation.
Dim re
Set re = New RegExp
re.IgnoreCase = True
re.Global = False
Set Pattern to the rule you want to test, then call Test(value). For validation, anchoring the expression with ^ and $ usually ensures the whole value is checked rather than just a matching substring.
Do not use a very restrictive pattern when valid real-world input is more varied than the pattern allows. Validate only what the application genuinely requires.
Dim re
Set re = New RegExp
re.Pattern = "^[A-Za-z0-9]{3,8}$"
re.IgnoreCase = True
Response.Write re.Test("A23")Output:
TrueThe anchors force the whole string to match. Test() returns True or False.
Anchor patterns with ^ and $ when the full input must match. Regular expressions do not replace authorization checks, parameterized database queries or safe HTML output.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.