This is a super basic question (I am brain dead today):
How do I validate in input using regexes, to see: 1) if the input is in a certain form 2) if the input is all caps (just casting the input to caps is not feasible for this)
I want ot make sure my inputs are in the form XX_XX. Here isi what I have:
public bool IsKosher(string input)
{
Regex r = new Regex(input);
if(r.Matches([A-Z]_[A-Z]))
{
return true;
}
return false;
}
Any ideas why it's not compiling?
Thank you!
You are missing double quotes, you put parameters in wrong places, and you do not need an if statement:
public bool IsKosher(string input) {
return Regex.IsMatch(input, "[A-Z]{2}_[A-Z]{2}");
}
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