RegExp question

H

Hulk

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
 
L

Larry Lard

Hulk said:
Hello!

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

For those following along: this regex does not match an empty string
Can anyone see whats wrong?

^(\d{5})?$
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top