-
Notifications
You must be signed in to change notification settings - Fork 4
/
form.html
44 lines (41 loc) · 1.39 KB
/
form.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
<!DOCTYPE html>
<html lang="en" ng-app="appModule">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css">
</head>
<body>
<div ng-controller="ctrl" class="container">
<form name="myform" novalidate="novalidate">
<div class="form-group">
<label for="email" class="control-label">邮箱</label>
<input type="email" id="email" name="email" ng-model="email" class="form-control" ng-required="true" ng-maxlength="3" ng-pattern="/^\d+$/">
</div>
<!--根据邮箱格式是否正确进行验证-->
<div class="alert alert-danger" ng-show="myform.email.$error.email">
邮箱格式不正确
</div>
`<div class="alert alert-danger" ng-show="myform.email.$error.required&&myform.email.$dirty">
必须填写
</div>
`<div class="alert alert-danger" ng-show="myform.email.$error.pattern">
正则不满足
</div>
<div>
<button class="btn-primary btn">提交</button>
</div>
</form>
<pre>
{{myform| json}}
</pre>
</div>
<script src="node_modules/angular/angular.js"></script>
<script>
//在使用angular验证时候,需要关闭h5自带的验证
var app = angular.module('appModule',[]);
app.controller('ctrl',function ($scope,$rootScope) {
});
</script>
</body>
</html>