Solved

RegularExpressionValidator Help

Posted on 2010-08-31
14
333 Views
Last Modified: 2013-11-05
I have a regularExpressionValidator that's failing on the text below and I don't know why.  I want my validator to allow all possible characters and force a minimum of 20 characters to be entered.

My validator is:

<asp:RegularExpressionValidator ID="revJustification" runat="server" ControlToValidate="txtJustification" ErrorMessage="Please provide a longer justification." ValidationExpression=".{20}" />

The text it's failing on is:

-           submission of pdf documents (merging, partial deletion of file etc) to clients

-           conversion to good quality pdf of quotations including hyperlink
0
Comment
Question by:scross1276
  • 6
  • 4
  • 2
  • +1
14 Comments
 
LVL 22

Expert Comment

by:pivar
ID: 33568077
Hi,

Try


<asp:RegularExpressionValidator ID="revJustification" runat="server" ControlToValidate="txtJustification" ErrorMessage="Please provide a longer justification." ValidationExpression=".{20,}" />

Yours would validate exactly 20 characters.

/peter

0
 

Author Comment

by:scross1276
ID: 33568107
I actually tried that after submitting this question and I still get my error message saying the justification needs to be longer.
0
 
LVL 5

Expert Comment

by:FredTang
ID: 33568156
ValidationExpression="\w{20,}"
0
 
LVL 5

Expert Comment

by:FredTang
ID: 33568252
please try :
ValidationExpression=".{20,}$"
0
 

Author Comment

by:scross1276
ID: 33568377
Still no luck.  I don't get it.  I tried both of your suggestions.

<asp:RegularExpressionValidator ID="revJustification" runat="server" ControlToValidate="txtJustification"
                        ErrorMessage="Please provide a longer justification." ValidationExpression=".{20,}$" />
0
 
LVL 9

Expert Comment

by:puru1981
ID: 33568391
why you have used (.)?
0
 

Author Comment

by:scross1276
ID: 33568467
A period (.) is the regularExpressValidator option for all characters.  At least I believe so.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 22

Expert Comment

by:pivar
ID: 33569974
The validator

<asp:RegularExpressionValidator ID="revJustification" runat="server" ControlToValidate="TextBox1" ErrorMessage="Please provide a longer justification." ValidationExpression=".{20,}" />           

works as intended for me in both asp.net 2.0 and 3.5

What kind of control is txtJustification?
0
 

Author Comment

by:scross1276
ID: 33570102
It's a standard textbox control.  <asp:textbox id="txtJustification" runat="Server" textMode="Multiline" />.
0
 
LVL 9

Expert Comment

by:puru1981
ID: 33570109
i usually use [0-9a-zA-z/w] for this so asked
0
 
LVL 9

Expert Comment

by:puru1981
ID: 33570165
can you share your aspx code
0
 

Author Comment

by:scross1276
ID: 33570300

<%@ Register TagPrefix="uc1" TagName="menu" Src="~/menu.ascx" %>



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="generalSoftware.aspx.cs"

    Inherits="eForms.generalSoftware.generalSoftware" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>General Software Request</title>

    <link rel="stylesheet" type="text/css" href="../site.css" />

    <link rel="stylesheet" type="text/css" href="../print.css" />

</head>

<body>

    <form id="software" method="post" runat="server">

    <uc1:menu ID="Menu" runat="server"></uc1:menu>

    <div id="content">

        <br />

        <div class="header1">

            Information Technology</div>

        <div class="header2">

            General Software License Request</div>

        <br />

        <br />

        <asp:Table ID="tblRequestInfo" runat="server" CellSpacing="2" Width="750" BorderWidth="0">

            <asp:TableRow>

                <asp:TableCell Width="300px">

                    Date of Request:

                </asp:TableCell>

                <asp:TableCell>

                    <asp:Label ID="lblRequestDate" runat="server" />

                </asp:TableCell>

            </asp:TableRow>

            <asp:TableRow>

                <asp:TableCell>

                    Requestor:

                </asp:TableCell>

                <asp:TableCell>

                    <asp:Label ID="lblRequestor" runat="server" />

                </asp:TableCell>

            </asp:TableRow>

            <asp:TableRow>

                <asp:TableCell>

                    Employee Name Needing Software:

                </asp:TableCell>

                <asp:TableCell>

                    <asp:TextBox ID="txtName" runat="server" Width="250px" />

                    <asp:RequiredFieldValidator ID="rfvName" ControlToValidate="txtName" Text="Name is required."

                        runat="server" />

                </asp:TableCell>

            </asp:TableRow>

            <asp:TableRow>

                <asp:TableCell>

                    Department of Employee Needing Access:

                </asp:TableCell>

                <asp:TableCell>

                    <asp:TextBox ID="txtDepartment" runat="server" Width="250px" />

                    <asp:RequiredFieldValidator ID="rfvDepartment" ControlToValidate="txtDepartment"

                        Text="Department is required." runat="server" />

                </asp:TableCell>

            </asp:TableRow>

            <asp:TableRow>

                <asp:TableCell>

                    Approving Supervisor:<br /><br />

                </asp:TableCell>

                <asp:TableCell>

                    <asp:DropDownList ID="ddlApprovingSupervisor" runat="server" Width="250px" />

                    <asp:RequiredFieldValidator ID="rfvApprovingSupervisor" runat="server" ControlToValidate="ddlApprovingSupervisor"

                        ErrorMessage="This field is required." InitialValue="-1" />

                </asp:TableCell>

            </asp:TableRow>

            <asp:TableRow>

                <asp:TableCell>

                    Business Unit of Employee Needing Access:

                </asp:TableCell>

                <asp:TableCell>

                    <asp:DropDownList ID="ddlBusinessUnit" runat="server" Width="325px">

                        <asp:ListItem Value=""></asp:ListItem>

                        <asp:ListItem>Corporate</asp:ListItem>

                        <asp:ListItem>Eastern Hemisphere</asp:ListItem>

                        <asp:ListItem>Manufacturing Supply Chain</asp:ListItem>

                        <asp:ListItem>Offshore Pipeline Solutions</asp:ListItem>

                        <asp:ListItem>Onshore Pipeline Solutions</asp:ListItem>

                        <asp:ListItem>Western Hemisphere</asp:ListItem>

                    </asp:DropDownList>

                    <asp:RequiredFieldValidator ID="rfvBusinessUnit" runat="server" ControlToValidate="ddlBusinessUnit"

                        ErrorMessage="BU is required." InitialValue="" />

                </asp:TableCell>

            </asp:TableRow>

            <asp:TableRow>

                <asp:TableCell>

            Software being Requested:

                </asp:TableCell>

                <asp:TableCell>

                    <asp:DropDownList ID="ddlSoftware" runat="server" Width="325px" OnSelectedIndexChanged="ddlSoftware_SelectedIndexChanged" AutoPostBack="true" />

                    <br />

                    <asp:RequiredFieldValidator ID="rfvSoftware" runat="server" ControlToValidate="ddlSoftware"

                        ErrorMessage="You must select a software title." InitialValue="" />

                </asp:TableCell>

            </asp:TableRow>

            <asp:TableRow>

                <asp:TableCell>

            <asp:label ID="lblSoftwareNotListed" runat="server" Visible="false">Software Title &amp; Price if Not Listed Above:</asp:label>

                </asp:TableCell>

                <asp:TableCell>

                    <asp:TextBox ID="txtSoftwareNotListed" runat="server" Width="200px" Visible="false" />&nbsp;<asp:TextBox ID="txtPrice" runat="server" Width="50px" Visible="false" />

                </asp:TableCell>

            </asp:TableRow>

            <asp:TableRow>

                <asp:TableCell>Business Justification for this Software:</asp:TableCell>

                <asp:TableCell>

                    <asp:TextBox ID="txtJustification" runat="server" TextMode="MultiLine" Rows="7" Columns="35"

                        MaxLength="500" /><br />

                    <asp:RequiredFieldValidator ID="rfvJustification" ControlToValidate="txtJustification"

                        Text="A business justification for this request is required." runat="server" /><br />

                    <asp:RegularExpressionValidator ID="revJustification" runat="server" ControlToValidate="txtJustification"

                        ErrorMessage="Please provide a longer justification." ValidationExpression=".{20,}" />

                </asp:TableCell>

            </asp:TableRow>

            <asp:TableRow>

                <asp:TableCell>Date Software is Needed:</asp:TableCell>

                <asp:TableCell>

                    <asp:Calendar ID="calDateNeeded" runat="server" BackColor="#585858" SelectedDayStyle-BackColor="#C90515"

                        SelectionMode="Day" TodayDayStyle-BackColor="#CFCFCF" TodayDayStyle-ForeColor="#000000"

                        CellPadding="0" CellSpacing="3" DayStyle-ForeColor="#FFFFFF" DayHeaderStyle-ForeColor="#CBCBCB"

                        DayNameFormat="FirstTwoLetters" Font-Size="8pt" TitleStyle-BackColor="#585858"

                        TitleStyle-Font-Bold="true" TitleStyle-ForeColor="#FFFFFF" OtherMonthDayStyle-ForeColor="#8E8E8E"

                        BorderColor="#000000" NextPrevStyle-ForeColor="#FFFFFF" OnSelectionChanged="calDateNeeded_SelectionChanged" />

                    <asp:TextBox ID="txtValidateCalendar" runat="server" CssClass="hideMe" />

                    <asp:RequiredFieldValidator ID="rfvCalendar" runat="server" ControlToValidate="txtValidateCalendar"

                        ErrorMessage="You must select a date." />

                </asp:TableCell>

            </asp:TableRow>

        </asp:Table>

        <br />

        <div style="text-align: center; font-size: 10pt">

            By clicking the submit button below, you acknowledge the cost of the software you

            selected, which will initially be paid for by IT, then charged back to your department

            through allocation costs.</div>

        <br />

        <div style="text-align: center">

            <asp:Button ID="btnSubmit" OnClick="btnSubmit_Click" Text="Submit Request" runat="server"

                CssClass="btn" />

        </div>

        <br />

    </div>

    <asp:TextBox ID="txtRequestID" runat="server" Visible="false" />

    <asp:TextBox ID="txtRequestDetailsID" runat="server" Visible="false" />

    <asp:TextBox ID="txtApprovalID" runat="server" Visible="false" />

    <asp:TextBox ID="txtEmail" runat="server" Visible="false" />

    </form>

</body>

</html>

Open in new window

0
 
LVL 9

Accepted Solution

by:
puru1981 earned 500 total points
ID: 33570519
0
 

Author Closing Comment

by:scross1276
ID: 33570743
I've tried that before, with success.  The only problem is that my expression string gets very long to accomodate all of the characters users enter.  That's ok, at least it worked.  I'll go back to that.  Thank you for you sticking with this and helping me!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

13 Experts available now in Live!

Get 1:1 Help Now