ASP Is Fun

Learning ASP
Free Course
Basics
Functions
SQL Commands
Sample Code


Servers / Setup
Host Reviews
Server Setup
Error Tips


Contract ASP
Development

Search For:


Intro to ASP


 


Writing Regular Expression Code



If you understand how wonderfully regular expressions can help you with your pattern matching needs, here is a walkthrough on creating ASP code.

First, be sure to read about the Basics of Regular Expressions to understand how these work.

So let's say we're taking in a social security number and want to validate that it has the proper 000-00-0000 format. You would do that with:

'Set Up the Expression'
Dim RegEx
Set RegEx = New regexp
RegEx.Pattern = "[0-9]{3}-[0-9]{2}-[0-9]{4}"
RegEx.Global = True
RegEx.IgnoreCase = True

SSNum = Input("SSNum")
if RegEx.Test(SSNum) = FALSE then response.redirect("error.asp")
Set RegEx = NOTHING

The "count" item tells you how many times that pattern was found in the search string. If it was not found at all, you know there was a problem. If somehow it was found MORE than one time, then you have a different sort of problem - maybe the user entered two social security numbers back to back.

This code can be used on creating phone numbers, social security numbers, usernames, passwords, or any other value that needs to have a set format.

ASP Basic Concepts



Bookmark this site so you can reference it any time you have ASP questions in the future!




ASP Main Page | ASP Ebooks | Free ASP Course |
All content copyright © 2012 Minerva WebWorks LLC. All rights reserved.

Exploring Believability


Free Newsletter!

Ebooks
Intro to ASP
ASP SQL DB
Members
Shopping


Introduction to ASP

Thought Provoking
Video Games and Child Soldiers

Romance Tips
Irish Romance
Italian Romance
French Romance

ASP Poll
How do you handle 500 errors?
I don't
Page does nothing
Displays error
Emails error