码迷,mamicode.com
首页 > Web开发 > 详细

中文输入验证AngularJS版

时间:2017-04-13 17:12:10      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:type   html   输入中文   set   blur   control   输入   验证   title   

<!DOCTYPE html>
<html ng-app="myApp" ng-controller="myCtrl" >
<head lang="en">
<meta charset="UTF-8">
<title>T63-中文输入验证AngularJS版</title>
<script src="js/angular.js" type="text/javascript"></script>
</head>
<body>
<input type="text" ng-model="iModel" ng-blur="iBlur()" ng-focus="iFocus()" />
<p >{{p}}</p>

</body>

<script type="text/javascript">
var app=angular.module("myApp",[]);
app.controller("myCtrl", function ($scope) {
$scope.iBlur = function(){
var reg = /^[\u4e00-\u9fa5][\s\u4e00-\u9fa5\s]*$/;
if (!reg.test($scope.iModel)) {
$scope.p = "请输入中文汉字";
$scope.iModel = "";
} else {
$scope.p= "输入合法";
}
};
$scope.iFocus= function () {
$scope.p="";
}


})




</script>

</html>

中文输入验证AngularJS版

标签:type   html   输入中文   set   blur   control   输入   验证   title   

原文地址:http://www.cnblogs.com/mx2036/p/6704373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!