June 28th, 2013, 08:57 AM
Simple Regex Help
I'm terrible with Regex, and I just need a very simple regex for a C# validator. It's basically a YouTube regex, however all the youtube regex's I've found in google searches actually have too many rules for what my client wants. Here's all I need to follow.
the URL must start with any of the following, potentially with http:// in front
that's it! lol. I admit I'm terrible with Regex's. I've tried doing this myself and been unsuccessful and it's at the point that this is taking too much time. Would love some help with this.
June 28th, 2013, 09:11 AM
not sure why you think you need a regex for this.
Fetch the domain from the URL (I guess the Uri class does this) and check if it starts with one of those three strings. That's it.
A regex is completely useless in this case, because you have constant strings rather than a pattern.
June 28th, 2013, 09:14 AM
well, I have several fields that are using different asp validators and are all part of a ValidationGroup so that all the error messages appear in the same alert.
June 28th, 2013, 09:42 AM
So you must use a single regex to validate the URL?
I guess you have to double all backslashes in C#. Plus you need to make the regex case-insensitive, because domains are as well.