I need help using a validation control in ASP.Net 3.5

Posted on 2011-05-09
Last Modified: 2012-05-11
Hi Experts,
I use a FileUpload control in my ASP.Net 3.5 application with codebehind.  I want to make sure that the file the user selects in the FileUpload control has the word ANNAUL and also the Word REPORT in it.  How can I use a Validation control to make sure that this is the case?

Thanks in advance,
Question by:mainrotor
    LVL 74

    Expert Comment

    by:käµfm³d 👽
    Try this one:
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
                                    ValidationExpression="^(?=.*?ANNUAL)(?=.*?REPORT).*$" />

    Open in new window

    LVL 4

    Accepted Solution

    why dont you use javascript instead of the code posted below if more custom work is needed

    Custom text:<br />
    <asp:TextBox runat="server" id="txtCustom" />
    <asp:CustomValidator runat="server" id="cusCustom" controltovalidate="txtCustom" onservervalidate="cusCustom_ServerValidate" errormessage="The text must be exactly 8 characters long!" />
    <br /><br />
    protected void cusCustom_ServerValidate(object sender, ServerValidateEventArgs e)
        var str=e.Value;
        var fileUpload=str.substring(0,str.indexOf(".")); // gets the name from the start and until "."
        var FileUploadName=fileUpload.toUpperCase()); //converts to uppercase for case insensitive
        if (FileUploadName=='ANNUAL' or FileUploadName=='REPORT')
     e.IsValid = true; //proceed with the upload
     e.IsValid = false; //does no upload

    Open in new window


    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    754 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

    19 Experts available now in Live!

    Get 1:1 Help Now