Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Валидация данных в HTML форме
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Javascript</title>
</head>
<body>
<p>введите число от 1 до 99</p>
<input id="number" type="text" >
<button type="button" onclick="myFunction()">Проверить</button>
<p id="result"></p>
<script>
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;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment