-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
50 lines (44 loc) · 1.39 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Number Validation</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
#result {
font-weight: bold;
margin-top: 20px;
}
</style>
</head>
<body>
<h2>Number Validation</h2>
<form id="validationForm">
<label for="inputString">Enter a string:</label>
<input type="text" id="inputString" name="inputString" required>
<br>
<button type="button" onclick="validateString()">Validate</button>
</form>
<div id="result"></div>
<script>
function validateString() {
// Get the input value
var inputString = document.getElementById('inputString').value;
// Regular expression to check if the string contains a number
var containsNumber = /\d/.test(inputString);
// Display result
var resultDiv = document.getElementById('result');
if (containsNumber) {
resultDiv.textContent = 'The entered string contains a number.';
} else {
resultDiv.textContent = 'The entered string does not contain any numbers.';
}
}
</script>
</body>
</html>