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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 343
  • Last Modified:

RegularExpressionValidator Help

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
scross1276
Asked:
scross1276
  • 6
  • 4
  • 2
  • +1
1 Solution
 
pivarCommented:
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
 
scross1276Author Commented:
I actually tried that after submitting this question and I still get my error message saying the justification needs to be longer.
0
 
FredTangCommented:
ValidationExpression="\w{20,}"
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
FredTangCommented:
please try :
ValidationExpression=".{20,}$"
0
 
scross1276Author Commented:
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
 
puru1981Commented:
why you have used (.)?
0
 
scross1276Author Commented:
A period (.) is the regularExpressValidator option for all characters.  At least I believe so.
0
 
pivarCommented:
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
 
scross1276Author Commented:
It's a standard textbox control.  <asp:textbox id="txtJustification" runat="Server" textMode="Multiline" />.
0
 
puru1981Commented:
i usually use [0-9a-zA-z/w] for this so asked
0
 
puru1981Commented:
can you share your aspx code
0
 
scross1276Author Commented:

<%@ 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
 
puru1981Commented:
0
 
scross1276Author Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now