首页 > 代码库 > 中文输入验证AngularJS版

中文输入验证AngularJS版

<!DOCTYPE html>
<html ng-app="myApp" ng-controller="myCtrl" >
<head lang="en">
<meta charset="UTF-8">
<title>T63-中文输入验证AngularJS版</title>
<script src="http://www.mamicode.com/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版