logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA
Irish Culture
Home Finance


dailyclick
All times in EST

Full Schedule
g
g ASP Site

BellaOnline's ASP Editor

g

Writing Regular Expression Code

Guest Author - Lisa Shea

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.
This site needs an editor - click to learn more!

Add Writing+Regular+Expression+Code to Twitter Add Writing+Regular+Expression+Code to Facebook Add Writing+Regular+Expression+Code to MySpace Add Writing+Regular+Expression+Code to Del.icio.us Digg Writing+Regular+Expression+Code Add Writing+Regular+Expression+Code to Yahoo My Web Add Writing+Regular+Expression+Code to Google Bookmarks Add Writing+Regular+Expression+Code to Stumbleupon Add Writing+Regular+Expression+Code to Reddit




RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the ASP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Lisa Shea. All rights reserved.
This content was written by Lisa Shea. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Best uses for RSS

RSS and its future.

Force Download Dialog box with ASP

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor