I want to detect if an IBAN account has all digits at zero 0, for example
00 0000 000 00 0000000000.
So I build this regex pattern to check it:
^(0\s){0,25}$
The argument would be: Check if the input string has only blank spaces or zeros.
But this does not work. Any help? Thank you.
Here is a non-regex example.
string input = "00 0000 000 00 0000000000";
bool isNotAllZeros = input
.Where(x => char.IsDigit(x))
.Any(x => x != '0');
It says: "get me all the digits from the string, and see if there are any that are not '0'."
Another method (to avoid double-negatives), using All, which might make more sense when reading:
bool isAllZeros = input
.Where(x => char.IsDigit(x))
.All(x => x == '0');
This says "are all the digits in the input '0'?"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With