There is a code, it does not allow the input of any characters, except natural numbers.
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript"> function check_field(id) { var field = document.getElementById(id); if (isNaN(field.value)) { alert('Помилка! Не дійсне число') } } </script> </head> <body> <form> Введіть дійсне число: <input type="text" id="t_field" onkeyup="this.value = this.value.replace(/\.(?=.*\.)|[^\d\.eE-]/g, '');"> <input type="button" value="Перевірити" onclick="check_field('t_field');"/> </form> </body> </html> I want to know how this line works, borrowed from another code.
<input type="text" id="t_field" onkeyup="this.value = this.value.replace(/\.(?=.*\.)|[^\d\.eE-]/g, '');">