-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
136 lines (129 loc) · 5.17 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>validation</title>
<meta name="description" content="">
<meta name="keywords" content="">
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<!-- <script src="/lib/angular_v1.2.16.js"></script> -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://rawgithub.com/tedshd/material_design_for_web/master/css/material_design_form.css">
<script src="https://rawgithub.com/tedshd/material_design_for_web/master/javascript/material_design_form.js"></script>
</head>
<body>
<h2>Basic Form validate</h2>
<form id="form" class="material-design-form" action="">
<div class="material-input-group">
<input class="validate-option" id="" type="text">
<label class="material-design-label" for="">E-mail</label>
</div>
<button type="submit">Submit</button>
</form>
<h2>Advance Form vaildate</h2>
<form id="form_1" class="material-design-form" action="">
<div class="material-input-group">
<input class="validate-option" id="email" type="text">
<label class="material-design-label" for="">E-mail</label>
</div>
<div id="pwd" class="material-input-group">
<input class="validate-option" type="password">
<label class="material-design-label" for="">PassWord</label>
</div>
<div class="error-msg"></div>
<button type="submit">Submit</button>
</form>
<h2>only number and eng validate</h2>
<form id="form_2" class="material-design-form" action="">
<div class="material-input-group">
<!-- <input class="validate-option" id="eng-num" type="text" onkeyup="value=value.replace(/[^\w=@&]|_/ig,'')"> -->
<input class="validate-option" id="eng-num" type="text">
<label class="material-design-label" for="">num & eng</label>
</div>
<button type="submit">Submit</button>
</form>
<h2>all blank validate</h2>
<form id="form_3" class="material-design-form" action="">
<div class="material-input-group">
<input class="validate-option" id="blank" type="text">
<label class="material-design-label" for="">not blank</label>
</div>
<button type="submit">Submit</button>
</form>
<h2>people id validate</h2>
<form id="form_4" class="material-design-form" action="">
<div class="material-input-group">
<input class="validate-option" id="peopleId" type="text">
<label class="material-design-label" for="">People id</label>
</div>
<button type="submit">Submit</button>
</form>
</body>
<script src="simple_form_validation.js"></script>
<script>
var validateForm = new validateForm;
// Basic Form validate
$('#form').on('submit', function(e) {
e.preventDefault();
alert(validateForm.email($('#form input').val(), 'Email Error'));
});
// Advance Form vaildate
var requiredStatus = 'pass';
$('#form_1').on('submit', function(e) {
e.preventDefault();
for (var i = 0; i < $('#form_1 .validate-option').length; i++) {
validate($('#form_1 .validate-option:eq('+ i +')'));
}
validateEmail();
});
$('#form_1 input').on('blur', function() {
validate($(this));
for (var i = 0; i < $('#form_1 .validate-option').length; i++) {
if (validateForm.required($('#form_1 .validate-option:eq('+ i +')').val()) !== 'pass') {
requiredStatus = 'fail';
$('#form_1 .validate-option:eq('+ i +')').parent().addClass('input-error');
$('#form_1 .error-msg').html(validateForm.required($('form .validate-option:eq('+ i +')').val()));
return;
} else {
requiredStatus = 'pass';
}
}
validateEmail();
});
function validateEmail() {
var email = validateForm.email($('#email').val());
if (requiredStatus === 'pass' && email !== 'pass') {
$('#email').parent().addClass('input-error');
$('#form_1 .error-msg').html(email);
return;
} else if (email === 'pass') {
$('#email').parent().removeClass('input-error');
}
}
function validate(input) {
var required = validateForm.required(input.val());
if (required !== 'pass') {
requiredStatus = 'fail';
input.parent().addClass('input-error');
$('#form_1 .error-msg').html(required);
} else {
requiredStatus = 'pass';
input.parent().removeClass('input-error');
$('#form_1 .error-msg').html('');
}
}
// number and eng validate
$('#form_2').on('submit', function(e) {
e.preventDefault();
alert(validateForm.engNum($('#eng-num').val()));
});
$('#form_3').on('submit', function(e) {
e.preventDefault();
alert(validateForm.allBlank($('#blank').val()));
});
$('#form_4').on('submit', function(e) {
e.preventDefault();
alert(validateForm.peopleId($('#peopleId').val()));
});
</script>
</html>