Julian Dormon
Julian Dormon

Reputation: 1779

regular expression for MVC validation

What would be the regular expression to find the substrings www. and http:// in a domain name.

Basically I am writing an MVC validation to disallow a word that includes www., http:// or http://www. in it.

Upvotes: 1

Views: 355

Answers (1)

Ant P
Ant P

Reputation: 25231

Try:

Regex.IsMatch(myString, @"(www\.|http://)");

If you want to specify that they aren't allowed at the start of the string, but allow them elsewhere, use:

Regex.IsMatch(myString, @"^(www\.|http://)");

Upvotes: 3

Related Questions