input text foramt validation code example

Example: number validation for textbox

BY LOVE
Use this function onkeypress event of the textbox
function isNumber(e)
{
        var specialKeys = new Array();
        specialKeys.push(8); //Backspace
        var keyCode = e.which ? e.which : e.keyCode
        var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
        return ret;
}

<input class="input--style-3" asp-for="@Model.PhoneNumber" 
onkeypress='return isNumber(event)' placeholder="Phone number">

Tags:

Misc Example