atljarman
asked on
ASP .Net C# public static bool
Hi,
Trying to create a public bool to return true/false if the url contains any invalid characters. I need the true/false for some other evaluation scripts that I have in my application. This is proabably pretty simple, but I have a class called mod and within mod is this class. I can't seem to retrieve the errors.
Trying to create a public bool to return true/false if the url contains any invalid characters. I need the true/false for some other evaluation scripts that I have in my application. This is proabably pretty simple, but I have a class called mod and within mod is this class. I can't seem to retrieve the errors.
public static bool IsSafe(string furl)
{
String theurl = furl;
bool safeUrl = true;
if (!theurl.IsNullOrEmpty) {
if theurl.IndexOf('=') != 0) {
safeUrl = false;
}
if theurl.IndexOf(':') != 0) {
safeUrl = false;
}
if theurl.IndexOf('=') != 0) {
safeUrl = false;
}
if theurl.IndexOf('?') != 0) {
safeUrl = false;
}
if theurl.IndexOf('&') != 0) {
safeUrl = false;
}
if theurl.IndexOf('#') != 0) {
safeUrl = false;
}
if theurl.IndexOf('(') != 0) {
safeUrl = false;
}
if theurl.IndexOf(')') != 0) {
safeUrl = false;
}
if theurl.IndexOf('<') != 0) {
safeUrl = false;
}
if theurl.IndexOf('>') != 0) {
safeUrl = false;
}
/*if theurl.IndexOf("\'") != 0) {
safeUrl = false;
}
if theurl.IndexOf('\"') != 0) {
safeUrl = false;
}*/
if theurl.IndexOf('!') != 0) {
safeUrl = false;
}
if theurl.IndexOf('@') != 0) {
safeUrl = false;
}
if theurl.IndexOf('$') != 0) {
safeUrl = false;
}
if theurl.IndexOf('%') != 0) {
safeUrl = false;
}
if theurl.IndexOf('^') != 0) {
safeUrl = false;
}
if theurl.IndexOf('*') != 0) {
safeUrl = false;
}
if theurl.IndexOf('+') != 0) {
safeUrl = false;
}
if theurl.IndexOf('~') != 0) {
safeUrl = false;
}
if theurl.IndexOf('|') != 0) {
safeUrl = false;
}
if theurl.IndexOf('{') != 0) {
safeUrl = false;
}
if theurl.IndexOf('}') != 0) {
safeUrl = false;
}
if theurl.IndexOf(']') != 0) {
safeUrl = false;
}
if theurl.IndexOf('[') != 0) {
safeUrl = false;
}
if theurl.IndexOf('\\') != 0) {
safeUrl = false;
}
if theurl.IndexOf(';') != 0) {
safeUrl = false;
}
if theurl.IndexOf(' ') != 0) {
safeUrl = false;
}
}
return safeUrl;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.