Regular Expression
http://www.csharpfriends.com
World's Greatest C# Community    
Home Articles C# Forums Books C# Syntax C# Spec C# Jobs free Source Code Advertise About
 

Control Panel

[ Sign In / register ]
Points   
Notes 
My Forums
My Tutorials
My Profile

Resources

Learn
 Articles
 QuickStarts
 C# Spec
 Whitepapers
 Tools
 Class Browser
 C# Code Generator
 Links
 Misc Rss Feeds
 Code Highlight
 411 Directory
 FREE magazines
 freevb.net

Reviews
  ASP.NET Hosting

Source Code
 Get Version 1.0



C# Consulting
AspDotNetStoreFront
Chapter:   UnCategorized
Current Lesson:
Regular Expression
[Latest Content]
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | ALL
[prev. Lesson]  Com Interop Tutorial [next Lesson]  Creating an XSD Schema using VS.Net Tools
Regular Expression
  by: Gsuttie

Regular Expression

by: Gsuttie

Regular Expression Tutorial

Within our business we have some rules for clientID's which must meet a certain length and format.

Within my project I created a class called Is.cs which I call when I want to check just what kind of client we have from the clientId entered in a textbox on the webpage.

Is.cs contains:
using System;
using System.Text.RegularExpressions;
Below is an example of some of the code I use within the project. I am checking here if the clientId is of TypeA and returns a boolean depending on the outcome. The code below is checking if the passed in string is 6 characters in length and has all numeric values.
public static bool IsTypeAId(string Value)
        {
            bool blnIs = false;
            blnIs = Regex.IsMatch(Value,
			      "^[0-9][0-9][0-9][0-9][0-9][0-9]$", 
RegexOptions.IgnoreCase);
            return blnIs;
        }
The code below is checking if the passed in string is 6 characters in length and starts with 2 letters followed by 4 numbers. The RegexOptions.IgnoreCase simply ignores case sensitivity and you can change this to check lower or upper case if the need arises.
public static bool IsTypeBId(string Value)
{
            bool blnIs = false;
            blnIs = Regex.IsMatch(Value,
			      "^[A-Z][A-Z][0-9][0-9][0-9][0-9]$", 
                RegexOptions.IgnoreCase);
            return blnIs;
}
Hope this is useful and slightly different from checking email address formats.

Any suggestions or comments you can email me at gsuttie@aol.com.

Thanks

Gregor


1 


Build Your Own ASP.NET Website Using C# & VB.NET

Chapter:  UnCategorized
Current Lesson:
Regular Expression
[Latest Content]
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | ALL
[prev. Lesson]  Com Interop Tutorial [next Lesson]  Creating an XSD Schema using VS.Net Tools


Today's Top Movers
vulpes 6800
MadHatter 2220
jal 867
Jeff1203 857
muster 791

Yesterday Top Movers
shakti sin.. 9
MadHatter 3
C#fanatic 2
Al_Pennywo.. 2
lilica 1

Monthly Leaders
vulpes 6800
MadHatter 2260
jal 867
Jeff1203 857
muster 791

Top Members
mosessaur 18457
Rincewind 7074
stanleytan 6995
vulpes 6800
Gsuttie 6046

Great Offers
.net hosting
Go To My Pc
Remote Pc Control
zonealarm
spam blocker
web hosting directory
ad server   C#
snadtech GoToMyPc

Top of Page

Advertise | About | Link To Us | Privacy Notice Copyright © 2003 - 2005 CSharpFriends.com  All Rights Reserved  Visual C# Developer Center