You don't need regular expression. This validation is already done in the class
System.Uri
, by its constructor. You can find an example here:
https://msdn.microsoft.com/en-us/library/system.uri.urischememailto%28v=vs.110%29.aspx[
^].
Also, you should handle and catch exceptions, as the string might not be valid. For the exceptions which can be thrown, please see:
https://msdn.microsoft.com/en-us/library/z6c2z492%28v=vs.110%29.aspx[
^].
If you don't expect "mailto:" in the test string, you have to prefix your input string with it. You can take it from
System.Uri.UriSchemeMailto
.
Put it all together to create the validation. As an additional bonus, you will get not just true/false answer, but, in case of successful validation, the instance of
Systen.Uri
, which is much more useful/informative than raw string.
—SA