Link to home
Start Free TrialLog in
Avatar of atljarman
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.

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;
    
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial