-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputValidation.html
More file actions
60 lines (55 loc) · 1.29 KB
/
inputValidation.html
File metadata and controls
60 lines (55 loc) · 1.29 KB
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
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" content="width=device-width,intial-scale=1.0" >
<style>
header
{
text-align:center;
padding:40px;
}
</style>
</head>
<body>
<header><h2>Numeric Input Validation </h2></header>
<div><lebal>Data:</lebal>
<input type="text" id="data" placeholder="Please enter the data">
<button onclick="promise_testing()">Submit</button>
<p id ="result"></p>
<h4 id ="alert"></h4>
<script>
function promise_testing()
{
let input=document.getElementById("data").value;
let result=document.getElementById("result");
let alert=document.getElementById("alert");
let prm = new Promise((resolve,reject)=>
{
if(/^[0-9]+$/g.test(input)&&(input.trim()!==""))
{
resolve(input);
}
else
{
reject(input);
}
});
prm
.then((massege)=>
{
result.style.color="green"
result.textContent=massege;
//you cant use console for web browser its for printing on the console
//avoid using console.log() directly on webpage it will not e print
alert.textContent="the input is valid✅";
})
.catch((error)=>
{
result.style.color="red"
result.textContent=error;
alert.textContent="Input is not valid ❌"
});
}
</script></div>
</body>
</html>