时间:2021-01-21 10:52:10 | 栏目:AngularJS | 点击:次
代码如下所示:
<form ng-app="myApp" ng-controller="validateCtrl" name="myForm" novalidate> <p>电话:<br> <input type="text" name="phone" ng-model="phone" ng-pattern="/(^$)|^(((\+86)|(86))?1[34578]\d{9})$/"> <span style="color:red" ng-show="myForm.phone.$dirty && myForm.phone.$invalid"> 联系电话格式不正确!</span> </p> <p> <input type="submit" ng-disabled="myForm.$invalid"> </p> </form>
正则表达式:
1. 匹配空:^$
2. 匹配手机号:^(((\+86)|(86))?1[34578]\d{9})$
3. 控制提示信息的显示:ng-show="myForm.phone.$dirty && myForm.phone.$invalid"