Created
October 8, 2014 04:03
-
-
Save lsongdev/5bd0c7fb608a7f53563e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- put file in your html --> | |
<script src="../common/forms/gh-pattern.js"></script> | |
<script src="../common/forms/gh-unique.js"></script> | |
<!-- require javascript to app --> | |
<script type="text/javascript"> | |
angular.module('ghValidation', [ 'ghPattern' ,'ghUnique' ]); | |
</script> | |
<!-- | |
validate-method 表示校验方式 | |
默认为 default, 也就是以 Angularjs 默认的 [立即校验] | |
可选的参数设置是 `blur`, 也就是 validate-method='blur' | |
这样的话就会当焦点离开 input 时才会触发校验 . | |
--> | |
<form validate-method='blur' > | |
<!-- | |
gh-unique 表示唯一性校验 | |
gh-unique 默认值等于 type 属性值(如果不写值的话) | |
--> | |
<!-- | |
gh-pattern 合法性校验 | |
gh-pattern 接收一个正则表达式字符串 | |
--> | |
<input name="email" type="email" | |
gh-unique="email" | |
gh-pattern="^\d+$" | |
/> | |
<!-- // --> | |
<span ng-show="form.email.$error.unique" >unique</span> | |
<span ng-show="form.email.$error.pattern" >pattern</span> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment