-
Notifications
You must be signed in to change notification settings - Fork 1
/
samarth form validation.html
86 lines (75 loc) · 3.01 KB
/
samarth form validation.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html>
<head>
<title> Form Submition </title>
<body>
<style>
#sam{
color: red;
padding: 50px;
}
#om{
color: red;
padding: 50px;
}
</style>
<form >
<label for="fname">First Name :- </label>
<input type="text" name="fname" id="st" placeholder="First Name"><br>
<span id="sam"></span><br>
<label for="lname">Last Name :-</label>
<input type="text" name="lname" id="nd" placeholder="Last Name" value=""><br>
<span id="om"></span><br>
<!-- <label for="mail">Email</label>
<input type="email" name="email" id="rd" placehold er="Email" value=""><br>
<span id="sami"></span> -->
<span id="sp"></span>
<input type="button" value="submit" name="submit" onclick="validation()"><br>
</form>
<script>
function validation() {
var user= document.getElementById("st").value;
var b= document.getElementById("nd").value;
var regex = /^[A-Za-z]+$/;
var regex1=/^[0-9]+$/;
if( user == "" ) {
document.getElementById("sam").innerHTML="*Please Enter your first name*"
document.getElementById("om").innerHTML="*Please Enter your last name*"
}
// if(regex.test(user)==true)
// {
// return true;
// }
// else
// {
// return false;
// }
// }
if(regex1.test(user)==true){
document.getElementById("sam").innerHTML="*Please enter only alphabets*"
}
if(regex1.test(b)==true){
document.getElementById("om").innerHTML="*Please enter only alphabets*"
}
}
// window.alert("Please enter your name.");
// name.focus();
// return false;
// }
// alert( "Please provide your name!");
// {
// var letters = /^[A-Za-z]+$/;
// if(regex.test(firstname)==true)
// {
// return true;
// }
// else
// {
// alert("message");
// return false;
// }
// }
</script>
</body>
</head>
</html>