Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2011-05-09
Medium Priority
Last Modified: 2012-05-11
Hi Experts,
I use a FileUpload control in my ASP.Net 3.5 application with vb.net 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 75

Expert Comment

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

Open in new window


Accepted Solution

Moizsaif123 earned 2000 total points
ID: 35764760
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

577 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