-
What are Different Ways to Input Only Numbers with HTML
over 5 years ago
-
about 5 years ago
hi,
html validations on input like number
can use javascript to check validations on input
can use libs like jquery or jquery validation engine -
-
about 5 years ago
hi,
you can use html validations.
javascript by targeting element or group of inputs
libs like jquery or jquery validattion engine -
-
about 5 years ago
// Restricts input for the given textbox to the given inputFilter. function setInputFilter(textbox, inputFilter) { ["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach(function(event) { textbox.oldValue = ""; textbox.addEventListener(event, function() { if (inputFilter(this.value)) { this.oldValue = this.value; this.oldSelectionStart = this.selectionStart; this.oldSelectionEnd = this.selectionEnd; } else if (this.hasOwnProperty("oldValue")) { this.value = this.oldValue; this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd); } }); }); } // Restrict input to digits and '.' by using a regular expression filter. setInputFilter(document.getElementById("myTextBox"), function(value) { return /^\d*\.?\d*$/.test(value); });
-
3 Answer(s)