Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Валидация данных в HTML форме
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<p>введите число от 1 до 99</p>
<input id="number" type="text" >
<button type="button" onclick="myFunction()">Проверить</button>
<p id="result"></p>
function myFunction(){
var number, result;
number = document.getElementById('number').value;
if (isNaN(number) || number < 1 || number > 99){
result = 'Число неверно';
} else {
result = 'Число верно';
document.getElementById('result').innerHTML = result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment