标签:directive angularjs validity
示例代码:
angular.module("myTest", []) .directive(‘multipleIdentityNo‘, [function () { return { require: "ngModel", link: function (scope, element, attr, ngModel) { if (ngModel) { var emailsRegexp = /^/d{17}[X0-9]{1}$/; //校验身-份-s-证号码 } var customValidator = function (value) { var validity = ngModel.$isEmpty(value) || emailsRegexp.test(value); ngModel.$setValidity("multipleIdentityNo", validity); return validity ? value : undefined; }; ngModel.$formatters.push(customValidator); ngModel.$parsers.push(customValidator); } }; }])
前端代码:
<input class="form-control" name="identityNo" type="text" multiple-Email-No ng-model="identityNo" placeholder="身-份-s-证号码"/>
那么重点来了:
如果
指令名 :multipleIdentityNo 为三个单词组成
那么
前端使用时必须使用"-" 分割每个单词(单词不区分大小写,反正最后还是会转为小写) 如:multiple-Email-No
本文出自 “aove” 博客,请务必保留此出处http://11101010211.blog.51cto.com/9388902/1630564
标签:directive angularjs validity
原文地址:http://11101010211.blog.51cto.com/9388902/1630564