Connecting Tech Pros Worldwide Forums | Help | Site Map

RegExp question

Hulk
Guest
 
Posts: n/a
#1: Apr 3 '06
Hello!

I have a following RegExp ^\d{5}?$
It should accept strings containing excatly fice numbers or an empty
string...
but it does not. Can anyone see whats wrong?

Code snippet checking this is below
// Sentence contains ^\d{5}?$

Regex RegExp = new Regex(Sentence, RegexOptions.IgnoreCase);
if(RegExp.Match(val).Success == false)
{
string text = "Validating Exception";
string keyAndValue = String.Format(" Key {0} with value {1} is
incorrect.", key, val);
throw new Exception(text + keyAndValue);
}


Cheers


Larry Lard
Guest
 
Posts: n/a
#2: Apr 3 '06

re: RegExp question



Hulk wrote:[color=blue]
> Hello!
>
> I have a following RegExp ^\d{5}?$
> It should accept strings containing excatly fice numbers or an empty
> string...
> but it does not.[/color]

For those following along: this regex does not match an empty string
[color=blue]
> Can anyone see whats wrong?[/color]

^(\d{5})?$

--
Larry Lard
Replies to group please

Closed Thread


Similar C# / C Sharp bytes