-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular1-6-form-validation.html
153 lines (134 loc) · 4.62 KB
/
angular1-6-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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<style>
.error {
color: red;
font-weight: bold;
}
</style>
<body>
<h2>Validation Example</h2>
<form ng-app="myApp" ng-controller="validateCtrl" name="myForm" novalidate>
<p>Username:<br>
<input type="text" name="user" ng-model="user" required>
<span style="color:red" ng-show="myForm.user.$dirty && myForm.user.$invalid">
<br>
<span ng-show="myForm.user.$error.required">Username is required.</span>
</span>
</p>
<p>Email:<br>
<input type="email" name="email" ng-model="email">
<span style="color:red" ng-show="myForm.email.$dirty && myForm.email.$invalid">
<br>
<span ng-show="myForm.email.$error.required">This field is required</span>
<br>
<span ng-show="myForm.email.$error.email">Invalid email address</span>
</span>
</p>
<p>Password:<br>
<input type="password" name="userPassword" ng-model="userPassword" required>
<ul class="error-list" ng-show="myForm.userPassword.$invalid" style="">
<li ng-show="submitted && myForm.userPassword.$error.required" class="error">
<label for="userPassword" class="orderSummaryError">This field is required</label>
</li>
<li ng-show="myForm.userPassword.$touched && myForm.userPassword.$error.isInvalidPassword" class="error">
<label for="userPassword" class="orderSummaryError">Password must be at least 8 characters and meet three of the fou