Thousand separator with MaskedEditExtender from the ASP.NET AJAX Control Toolkit

1.4k Views Asked by At

I need to format some inputs in an Textbox and I've tried to do so with the MaskedEditExtender. I don't know what mask I have to use to get what I want - maybe somebody knows.

The entered values are only numeric values with amounts between 100 and 9999999 Euros an I want to show the thousand separators an cent separators while typing into the textbox like this:

Input: 100 Show: 100,00

Input: 345000,50 Show: 345.000,50

To be more specific I want the exact same behavior like typing numeric values into an calculator and the kind the calculator shows the entered values on the display.

Here is an (expensive) example with exact the behavior I need for free: https://demos.devexpress.com/ASPxEditorsDemos/Features/MaskedInput.aspx

This is my code:

<asp:TextBox ID="purposeAmount" CssClass="textBoxCreateItem" OnTextChanged="purposeAmount_OnTextChanged" AutoPostBack="true" runat="server"></asp:TextBox> 
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="purposeAmount" Display="Dynamic" SetFocusOnError="true" ErrorMessage="Only numeric allowed." ForeColor="Red" ValidationExpression="^\d+(\,\d+$)?$" ValidationGroup="NumericValidate"><br />Erlaubte Zeichen: 0-9 und ,</asp:RegularExpressionValidator>
                <asp:RequiredFieldValidator id="RequiredFieldValidator4" runat="server" ControlToValidate="purposeAmount" ValidationGroup="NumericValidate" Display="Static" ForeColor="Red"><br />Eingabe erforderlich.</asp:RequiredFieldValidator>
<cc1:MaskedEditExtender TargetControlID="purposeAmount" MaskType="Number" Mask="9,999.99" runat="server" />
1

There are 1 best solutions below

5
On

Try this:

<ajax:MaskedEditExtender ID="MaskedEditExtender2" Mask="9,999.99"...</ajax:MaskedEditExtender>