-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjqueryValidation.html
52 lines (44 loc) · 1.16 KB
/
jqueryValidation.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
<!DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<form id="frm" action="next.html">
First name:<br>
<input id="ip1" type="text" name="firstname" placeholder="Name">
<br>
Email:<br>
<input id="ip2" type="email" name="mail" placeholder="Email">
<br><br>
<input id="subBtn" type="submit" value="Submit">
<p id="error" style="color:red"></p>
</form>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous">
</script>
<script>
$("#subBtn").click(function(e){
e.preventDefault();
var flag = 1;
var emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
$("#error").html("");
if( $("#ip1").val() == "" ){
flag = 0;
$("#error").append("Enter name<br>");
}
if( $("#ip2").val() == "" )
{
flag = 0;
$("#error").append("Enter email");
}
else if( ! emailRegex.test( $("#ip2").val() ) )
{
flag = 0;
$("#error").append("Enter valid email");
}
if( flag == 1 )
{
$("#frm").submit();
}
});
</script>
</body>
</html>