B
Byron
All I am trying to do is use Regex.IsMatch to validate that a string is
either empty, or exactly 4 characters (digits) in length. In other words,
the strings, "", and "1234" should pass, whereas "123", "abcd", and "12345"
should fail. I know there has to be a simple answer to this, but right now
I can't find it. I tried using:
if (str.Length == 0)
return true;
if (Regex.IsMatch(str, "[0-9]^4"))
return true;
but this does not work. Variations such as
Regex.IsMatch("1234", @"\d\d\d\d") come close, but also result in "12345"
validating.
Any help would be greatly appreciated.
either empty, or exactly 4 characters (digits) in length. In other words,
the strings, "", and "1234" should pass, whereas "123", "abcd", and "12345"
should fail. I know there has to be a simple answer to this, but right now
I can't find it. I tried using:
if (str.Length == 0)
return true;
if (Regex.IsMatch(str, "[0-9]^4"))
return true;
but this does not work. Variations such as
Regex.IsMatch("1234", @"\d\d\d\d") come close, but also result in "12345"
validating.
Any help would be greatly appreciated.