Help with Validation

Posted on 2008-11-10
Last Modified: 2012-05-05

I have the following line

if (rblEvaluation.SelectedValue == "Evaluation" && (!EvalURL.Contains("http://") && !EvalURL.Contains("https://")))

I've been told this is wrong, it should validate the begining of the string i.e.

it should check to see if http://    or   https://    appears at the beining of the string, the problem with the above is it validates the string anywhere in the string.

Hope this makes sense?

Question by:mousemat
    LVL 8

    Accepted Solution

    I assume you want to handle this if EvlaURL starts with http:// OR https:// otherwise it will always evaluate to false.

    if (rblEvaluation.SelectedValue == "Evaluation" && (!EvalURL.StartsWith("http://") || !EvalURL.StartsWith("http://")))

    Open in new window


    Author Comment

    Thanks OBonio, I thought I'd had to do something like indexOf, substring etc to get this to work.

    Thanks again
    LVL 16

    Expert Comment

    by:Gyanendra Singh
    use EvalURL.StartWith

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now