I have a text box that is using a RegularExpressionValidator to check that a string is in the correct format, and it is taking roughly 20 seconds to check. Is there a way to speed it up?
<asp:TextBox runat="server" ID="txtNumber"
width="9 em"
text='<%#Eval("strNumber")%>' AutoPostBack="true"
MaxLength="16" ontextchanged="txtNumber_TextChanged" />
<asp:RegularExpressionValidator
ID="NumberLength"
runat="server"
ValidationExpression="^\S{13,16}$"
ErrorMessage="Invalid Number"
Display="None" ControlToValidate="txtNumber"/>
<ajax:ValidatorCalloutExtender
ID="ValidatorCalloutExtender1"
runat="server" TargetControlID="NumberLength">
</ajax:ValidatorCalloutExtender>
Related
I have a RadMaskedTextBox for SSN while entering value in it, the first two characters are clearing up itself and getting RegularExpressionValidator message. Can some body help me in this.This problem exits in IE browsers only.
<span id="SSN" runat="server">*</span>Social Security Number</label>
<asp:RegularExpressionValidator ID="TaxId_RegEx"
runat="server" ControlToValidate="TaxId"
Display="None" ValidationExpression="^\d{3}\-\d{2}\-\d{4}$" ErrorMessage="Please enter a valid 9 digit SSN." Enabled="true"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="TaxId_ReqField"
runat="server" ControlToValidate="TaxId"
Display="None" ErrorMessage="Please enter a value for this required field."></asp:RequiredFieldValidator>
<radI:RadMaskedTextBox CssClass="box_SSN" SelectionOnFocus="SelectAll" ID="TaxId"
Width="85px" Mask="###-##-####" runat="server">
</radI:RadMaskedTextBox>
Try:
^\d{3}-\d{2}-\d{4}$
Instead of:
^\d{3}\-\d{2}\-\d{4}
This is working perfectly for me in IE:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBox1" Text="*">
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
runat="server"
ValidationExpression="\d{3}-\d{2}-\d{4}"
ControlToValidate="TextBox1"
ErrorMessage="Input valid SSN!">
</asp:RegularExpressionValidator>
<asp:Button ID="Button1" runat="server" Text="Submit"/>
Not sure why you have
Display="None"
I want validation expression for required field validator and the numeric validator together
for phone number
<asp:TextBox ID="txtPhonenumber" runat="server" MaxLength="11" TabIndex="11" onKeyPress="return validateNumbersOnly();" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Enter Phone Number" ControlToValidate="txtPhonenumber" ></asp:RequiredFieldValidator>
this code works only if field is empty
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtPhonenumber" ErrorMessage="Only Numbers" Display="None" ValidationExpression="^\d+$" ></asp:RegularExpressionValidator>
ValidationExpression="^\d+$"
use this for numeric format validation
<asp:TextBox ID="txtPhonenumber" runat="server" MaxLength="11" ></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter Phone Number" ControlToValidate="txtPhonenumber" ></asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtPhonenumber" ErrorMessage="Only Numbers" Display="None" ValidationExpression="^\d+$" ></asp:RegularExpressionValidator>
I have a RequiredFieldValidator. The code is below:
<asp:TextBox runat="server" ID="phone" MaxLength="10" Columns="10"
Width="90px"></asp:TextBox>
<asp:MaskedEditExtender ID="phone_MaskedEditExtender" runat="server" CultureAMPMPlaceholder=""
CultureCurrencySymbolPlaceholder="" CultureDateFormat="" CultureDatePlaceholder=""
CultureDecimalPlaceholder="" CultureThousandsPlaceholder="" CultureTimePlaceholder=""
Enabled="True" TargetControlID="phone" Mask="(999)999-9999" ClearMaskOnLostFocus="False">
</asp:MaskedEditExtender>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidatorPhone" ControlToValidate="phone"
ErrorMessage="Phone is required." Display="Dynamic" InitialValue="" />
If I remove the asp:MaskedEditExtender, the RequiredFieldValidator functions as expected. Otherwise it seems the validator loses its functionality.
Why?
Thanks.
Your MaskedEditExtender isn't doing anything but declaring a mask, and putting itself in the place of the value of your input.
All those Cultures are not needed in the case of a phone number.
What is the validation expression?
The whole point of the MaskedExtender is to control the input type. If you are using ASP you can do this by pulling from database and restricting the max length of the field.
Here is an example.
<cc1:MaskedEditExtender ID="MaskedEditExtender1"
runat="server"
TargetControlID="txtClientLookupValue"
Mask="999999-9999"
ClearMaskOnLostFocus="false">
</cc1:MaskedEditExtender>
<cc1:MaskedEditValidator ID="MaskedEditValidator1"
ControlExtender="MaskedEditExtender1"
runat="server"
ControlToValidate="txtClientLookupValue"
IsValidEmpty="True"
InvalidValueMessage="INVALID"
ValidationExpression="^[2-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$"
Display="Dynamic">
</cc1:MaskedEditValidator>
And here is a reference:
MaskedEditExtenderLinkASP
Good Luck.
Here is how I do phone numbers in ASP.NET (mask and validation). Just trying to help!
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="txb_HomePhoneNumb"
Cssclass="BoxStyleHireAppCityStateZip" runat="server"
Width="175" MaxLength="12">
</asp:TextBox>
<%--MaskedEditExtender Created with: ASP.NET AJAX Control
Toolkit: https://ajaxcontroltoolkit.codeplex.com--%>
<cc1:MaskedEditExtender ID="MaskedEditExtenderHomePhoneNumb"
runat="server"
TargetControlID="txb_HomePhoneNumb"
ClearMaskOnLostFocus ="false"
MaskType="None"
Mask="(999) 999-9999"
MessageValidatorTip="true"
InputDirection="LeftToRight"
ErrorTooltipEnabled="True"
/>
<asp:RegularExpressionValidator runat="server"
ControlToValidate="txb_HomePhoneNumb" style="color:red;"
CssClass="display-next"
ErrorMessage="*Not a valid phone number!"
ValidationExpression="^\D?(\d{3})\D?\D?(\d{3})\D?
(\d{4})$" Font-Size="Medium">
</asp:RegularExpressionValidator>
</div>
I have created a User Control for my SharePoint, which has a simple TextBox and a CheckBoxList. For both of these controls, I have ASP:RequiredFieldValidator and ASP:RegularExpressionValidator.
When I select some item in the CheckBoxList or type some input in the TextBox, I am getting a javascript error in some unknown location. (This is not accepted by my customer.)
Now, when I debug this using FireBug, in the console I see validators[i] is null. It is actually failing in the JS code generated by these validators.
Can some one help me?
Edited:
<asp:TextBox ID="txtNumbers" runat="server" CssClass="Label4" ></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidatorGPC" runat="server"
ControlToValidate="txtNumbers" ErrorMessage="Only Numbers Accepted "
ValidationExpression="^\d+$"
SetFocusOnError="true"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredNUMValue" runat="server" ControlToValidate="txtNumbers"
SetFocusOnError="true" ErrorMessage="Please enter a valid number"></asp:RequiredFieldValidator>
Also,
I added required field validators for RadioButtonList (not CheckBoxList).
<asp:RadioButtonList ID="rbtOptions" runat="server" CssClass="Label3">
<asp:ListItem Text="Option 1" />
<asp:ListItem Text="Option 2" />
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="rbtOptions"
SetFocusOnError="true" ErrorMessage="Please Select a Valid Option"></asp:RequiredFieldValidator>
When I either input any text in the TextBox or select any option, there is a JavaScript error.
There is something else on your page that is conflicting with this. Taking what you posted and trying a simple page it works as it should, so I'm assuming that there's other elements / scripts that are causing this.
<div>
<asp:TextBox ID="txtNumbers" runat="server" CssClass="Label4"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidatorGPC" runat="server" ControlToValidate="txtNumbers" ErrorMessage="Only Numbers Accepted " ValidationExpression="^\d+$" SetFocusOnError="true"></asp:RegularExpressionValidator>
<asp:RequiredFieldValidator ID="RequiredNUMValue" runat="server" ControlToValidate="txtNumbers" SetFocusOnError="true" ErrorMessage="Please enter a valid number"></asp:RequiredFieldValidator>
<asp:RadioButtonList ID="rbtOptions" runat="server" CssClass="Label3">
<asp:ListItem Text="Option 1" />
<asp:ListItem Text="Option 2" />
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="rbtOptions" SetFocusOnError="true" ErrorMessage="Please Select a Valid Option"></asp:RequiredFieldValidator>
<asp:Button ID="btnSubmit" runat="server" Text="submit" />
</div>
Do you have any script tags, or other elements in your markup that could be interfering with this?
Self closed tags can cause issues like this ( is a no no)
is this following a proper date validation fn
<asp:TextBox ID="date" Width="80px" MaxLength="10" runat="server" />
</td>
<td>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="date"
ErrorMessage="date. " ValidationExpression="^(\d{4})(\d{2})(\d{2})$" Display="Static" Font-Names="Arial"
Font-Size="11" runat="server">
enter a valid date formate
</asp:RegularExpressionValidator>
I believe this would be a better approach, use what's built-in:
<asp:TextBox ID="date" Width="80px" MaxLength="10" runat="server" />
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="date" ErrorMessage="* Enter a valid date"
Operator="DataTypeCheck" Type="Date" />
The key settings are Operator and Type.
Note if you have to consider multiple cultures and such, this becomes a much more involved question, hopefully that isn't the case.