10/03/2024

Code function validate Input number in textbox only.

 

Code function validate Input number in textbox only.
html
  1. <input type="text" id="test_id" name="test" value="" oninput="validateInput(event)">

js function

  1. function validateInput(event) {
  2.    var input = event.target.value;
  3.    if (!/^[0123456789 ]*$/.test(input)) {
  4.       event.target.value = input.replace(/[^0123456789 ]/g, '');
  5.    }
  6. }

No comments:

Post a Comment