We have an asp.net page that allows user to enter a decimal number and are using a FilteredTextboxExtender to only allow numbers and a decimal point as shown below.
However, it still allows a user to enter something like 1.1.1 which fails when trying to do an update. Is there a way in JavaScript or jQuery that I can find this before the postback?
I know this is going to sound crazy but after 1400+ posts have you considered simply reviewing the validation server controls documentation to see what standard validation controls are available in ASP.NET? You could start by clicking on the validation
menu in the toolbox to see what there.... I see three controls that seems rather inviting; the regular expression, compare, and custom validator. Maybe investigate each and see if one fits... You might find two or even three...
We attached sample code for the .cshtml page.
You have to add reference related to the AjaxControlToolkit in to the .cshtml page and add same reference into References into our project.
You can download dll "AjaxControlToolkit" from https://www.dllme.com/dll/files/ajaxcontroltoolkit_dll.html
.cshtml page
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
function IsOneDecimalPoint(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode; // restrict user to type only one . point in number
var parts = evt.srcElement.value.split('.');
if(parts.length > 1 && charCode==46)
return false;
return true;
}
</script>
<asp:TextBox ID="txtFoodPro" runat="server" Text='<%# Bind("FoodPro") %>' Width="50" onchange="CalcCalories(this);" onkeypress="return IsOneDecimalPoint(event);" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Required entry" ControlToValidate="txtFoodPro" Display="Dynamic" />
<ajax:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" FilterType="Custom" ValidChars="01234567890." TargetControlID="txtFoodPro"></ajax:FilteredTextBoxExtender>
</asp:Content>
If you still facing issue please share your .cshtml page code so that we can identify error.
Yes, I considered this but I wanted a solution that was outside of the validation controls so I could use it on any page. And the regular expression is pretty confusing. Thanks.
Member
353 Points
1549 Posts
Find multiple occurance in string
Dec 26, 2019 10:24 PM|dlchase|LINK
We have an asp.net page that allows user to enter a decimal number and are using a FilteredTextboxExtender to only allow numbers and a decimal point as shown below.
However, it still allows a user to enter something like 1.1.1 which fails when trying to do an update. Is there a way in JavaScript or jQuery that I can find this before the postback?
All-Star
53001 Points
23587 Posts
Re: Find multiple occurance in string
Dec 26, 2019 11:17 PM|mgebhard|LINK
I know this is going to sound crazy but after 1400+ posts have you considered simply reviewing the validation server controls documentation to see what standard validation controls are available in ASP.NET? You could start by clicking on the validation menu in the toolbox to see what there.... I see three controls that seems rather inviting; the regular expression, compare, and custom validator. Maybe investigate each and see if one fits... You might find two or even three...
Participant
850 Points
492 Posts
Re: Find multiple occurance in string
Dec 27, 2019 07:00 AM|AddWeb Solution|LINK
Hello dlchase,
We attached sample code for the .cshtml page.
You have to add reference related to the AjaxControlToolkit in to the .cshtml page and add same reference into References into our project.
You can download dll "AjaxControlToolkit" from https://www.dllme.com/dll/files/ajaxcontroltoolkit_dll.html
.cshtml page
If you still facing issue please share your .cshtml page code so that we can identify error.
Thanks.
Member
353 Points
1549 Posts
Re: Find multiple occurance in string
Dec 27, 2019 03:16 PM|dlchase|LINK
Yes, I considered this but I wanted a solution that was outside of the validation controls so I could use it on any page. And the regular expression is pretty confusing. Thanks.