Search results

Display numeric keypad when focus on mobile devices in ASP.NET MVC MaskedTextBox control

29 Jul 2021 / 1 minute to read

By default, on focusing the MaskedTextBox, alphanumeric keypad will be displayed on mobile devices. Sometimes only numeric keypad for number values is needed, and this can be achieved by setting “type” property to tel. Refer to the following example to enable numeric keypad in MaskedTextBox.

razor
numericKeypad.cs
Copied to clipboard
@Html.EJS().MaskedTextBox("mask1").Mask("000-000-0000").Created("onCreate").Render()

<script>
    function onCreate() {
        var key = document.getElementById("mask1");
        key.type = "tel";
    }
</script>
Copied to clipboard
public ActionResult numericKeypad()
{
    return View();
}