Brad,
Try this:
public static Regex regex = new Regex(
@"\b\d{7}\b|\b\d{8}\b",
RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
Do not let the \b expressions throw you. Additionally, you may want to
download Expresso from
http://www.ultrapico.com/. It is the best regex
tutorial/utility I have found over the years.
--------------------
Quote:
>From: "Brad Prendergast" <format('bradp%sbpsoftware.com',['@'])>
>Subject: Re: More regular expression woes
>References: <ud4wgxvQHHA.4744@TK2MSFTNGP02.phx.gbl>
>User-Agent: XanaNews/1.18.1.5
>Message-ID: <xn0f1qvzhcrzq1000@msnews.microsoft.com>
>X-Ref: msnews.microsoft.com ~XNS:00000018
>Newsgroups: microsoft.public.dotnet.languages.csharp
>Date: Sun, 28 Jan 2007 09:11:35 -0800
>NNTP-Posting-Host: c-76-19-190-126.hsd1.ma.comcast.net 76.19.190.126
>Lines: 1
>Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSF TNGP03.phx.gbl
>Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.dotnet.languages.csharp:11378
>X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
>
>Mark Rae <mark@markNOSPAMrae.comwrote in message
><ud4wgxvQHHA.4744@TK2MSFTNGP02.phx.gbl>:
>
Quote:
>>Hi,
>>
>>This time, I'm looking for a regular expression which says "the
>>string must contain exactly seven or exactly eight digits" e.g.
>>
>>123456 fails
>>1234567 passes
>>12345678 passes
>>123456789 fails
>>
>>I've tried this:
>>
>>\d{7,8}
>>
>>but that allows 123456789 to pass, presumably because it contains a
>>string of seven or eight digits...
>>
>>Is there any way to specifiy a fixed length to validate?
>>
>>Any assistance gratefully received.
>>
>>Mark
>
Regex r;
r = new Regex("^\\d{7,8}$");
>
>--
>Brad Prendergast
>"There's a fine line between genius and insanity. I have erased this
>line." -- Oscar Levant (1906 - 1972)
>
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl {\f0\fnil\fprq2\fcharset0
MS Sans Serif;}{\f1\fswiss\fcharset0 Arial;}}
{\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\f0\fs20 Cheers,\par
\par
johnKn [MS-SDK]\par
\par
\par
\par
-Please do not send email directly to this alias. This alias is for \par
newsgroup purposes only\par
\par
-This posting is provided "AS IS" with no warranties, and confers no
rights.\par
\par
-To provide additional feedback about your community experience please send
\par
e-mail to:
sdkcomm@microsoft.com\par
\f1\par
}