I have a string that needs to be the following format: XX999900.
XX has to be only character no decimal followed by 6 digits.
So I thought of using regex in the following way:
string sPattern = @"^\\[A-z]{2}\\d{6}$";
indexNumber = "ab9999.00";
if (Regex.IsMatch(indexNumber, sPattern)
{
// do whatever
}
It fails.
Can somebody tell me what is wrong?
I don’t believe
[A-z]is a valid character class. You certainly do not need\\when using@.Try this:
If you need the format to have 4 numerals followed by a
.then two more numerals, try this:(Note that for .NET,
\dwill match numerals in any script, so you may want to replace it with[0-9]if you want to only match those)