Regular Expressions

Last post 05-15-2008 10:33 AM by PoornimaS. 2 replies.

Sort Posts:

  • Regular Expressions

    05-14-2008, 4:51 PM
    • Loading...
    • PoornimaS
    • Joined on 08-21-2007, 4:04 PM
    • Posts 9

    I have a file upload control in which I want to allow only pdf files. I am using the following validation expression
    "^((^$)|((([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.pdf|.PDF)$))".  It works fine except when there is a server side validation fails and the page returns with error, my file upload regular expression error message also popsup. 
    Any suggestions would help.

  • Re: Regular Expressions

    05-14-2008, 6:38 PM
    • Loading...
    • johram
    • Joined on 06-13-2006, 6:36 AM
    • Sweden
    • Posts 3,171
    • Moderator

    What does your code for server-side validation do? This is some custom code outside the validator?

    If this post was useful to you, please mark it as answer. Thank you!
  • Re: Regular Expressions

    05-15-2008, 10:33 AM
    • Loading...
    • PoornimaS
    • Joined on 08-21-2007, 4:04 PM
    • Posts 9

    I am not using a custom validator.  During Post Back I am checking for few values and returning the page according to that. eg: I have a agreement checkbox, If it is not checked

    An error label is shown with the same page. That is the case my FileUpload Control's Error Message also shown up.

     

    Here is the code for my FileUpload

    <asp:FileUpload ID="UploadFile" runat="server" Width="182" />

    <asp:RegularExpressionValidator ID="PDFValidator" runat="server" ControlToValidate="UploadFile" Display="None" ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.pdf|.PDF)$"

    ErrorMessage="<%$ Resources:My_Mannatech:MeetingModifyCreate:FileSizeMessage.Text %>" SetFocusOnError="true" ></asp:RegularExpressionValidator></td>

    and my Code Behind is

    protected void NextButton_Click(object sender, EventArgs e)

    {

    if (AgreementCheckBoxID.Checked && createMeetingControl.IsAllDataValid())

    {

    ErrorMessage.Visible =
    false;

    CheckBoxErrorLabel.Visible = false;

    PreviousButtonID.Visible = true;NextButton.Visible = false;

    SubmitButton.Visible = true;

    AgreementCheckBoxID.Enabled = false;

    }

    else

    {

    if (!AgreementCheckBoxID.Checked)

    CheckBoxErrorLabel.Visible = true;

    else

    CheckBoxErrorLabel.Visible = false;

     }

    }

Page 1 of 1 (3 items)