C # ASP.NET Application Regular Expression
For C # ASP.NET application - This should be simple, but I can't figure out this regex, I need a list of strings that the textbox cannot represent as a value, and I have to ignore the case.
Example - Regardless of capitalization, I need my regex to reject the following lines: abc, def, ghi
I can't even get the regex to reject one of them. I tried the following:
[RegularExpression(@"(\W|^)(?i)!ABC(?-i)(\W|$)", ErrorMessage = "REJECTED!")]
public string Letters { get; set; }
This does not work! It seems to reject everything. Does anyone know what it should look like? How can I give up all of them?
Thanks for any help you can provide!
source to share
This will detect abc, def and ghi
(?i)(abc|def|ghi)
enclose in ^
and $
only match with them and nothing else (for example will not match wxabcyz)
^(?i)(abc|def|ghi)$
Finally, if you want to match something like "This is some kind of random abc text" and reject it, do this
(?i)\b(abc|def|ghi)\b
source to share
^((?!abc)|(?!def)|(?!ghi).)*$
That's about it.
Btw I would recommend that you play around with something like the following resources that you are not already.
regex pal
and regular-expressions.info
source to share