I want to prevent users from entering url\'s (like a href=\"\") in a TextBox.
I want to use a regular expression validator but no idea what to write?
How ca
Do you mean you literally want to prevent them from entering the text href="
in the TextBox, or you want to prevent URLs? Either way, a RegexValidator is one solution:
Actually, as far as I know there is not a very easy way to use an OOTB-regex validator to do a negative contains (i.e. "fail if any match"). Someone smarter may be able to correct me on that. But you can definitely use a custom validator:
Codebehind:
protected void ValidateNoUrls(object sender, ServerValidateEventArgs e)
{
e.IsValid = !Regex.IsMatch(e.Value, @"(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?");
}