Skip to content

Instantly share code, notes, and snippets.

@MuratOrs
Created March 11, 2016 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MuratOrs/9aaca0f5d7a281cb090a to your computer and use it in GitHub Desktop.
Save MuratOrs/9aaca0f5d7a281cb090a to your computer and use it in GitHub Desktop.
Валидация данных в 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