Validate Textbox for Numbers Only

I need a textbox that allows the user to enter only numbers. When they enter the value, they can click an Add button to add the item to a list.

I've tried validating the input using Regex but still allows letters and the add button still adds an invalid item to the list.

How can I either:

  1. Only allow numbers entered in the textbox? If a letter is entered, it is ignored and does not show up in the textbox. Or...
  2. Validate just the textbox control when the Add button is clicked? I've tried using the templateForm.EditContext.Validate() method but that validates the entire form and then stops the textbox from allowing input afterwards.


You can use RadzenNumeric component.

I need to be able to support leading zeros so a Numeric component will not work.

You can try RadzenMask also.