I have a model string which looks like:
bla bla bla <b>asdad</b> bla bla bla bla <u>bla</u> ...
My model:
public class MyModel {
[RegularExpression( @"^(<\s*([^ >]+)[^>]*>.*?<\s*\/\s*\1\s*>)$", ErrorMessage = "No tag is allowed !")]
public string Text { get; set; }
}
I tried to negate above regex ( I know that I didn't use correctly and I don't know how to do this correctly)
I want to show error when Text
contains any match of HTML code, even it has no closed tag, means should occur when met:
<b>
without </b>
</b>
or similar
How to achieve this with regex ?
This is the regex for that:
<(\s*[(\/?)\w+]*)
It checks for even if single closing tag is there or opening tag is there, it matches that.
DEMO here
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