用于设置输入框的正则表达式
用法:
<html ng-app="extendApp"> <head> <meta charset="UTF-8"> <title></title> </head> <body ng-controller="extendController"> <div> <form name="form"> <label for="regex">Set a pattern (regex string): </label> <input type="text" ng-model="regex" id="regex" /> <br> <label for="input">This input is restricted by the current pattern: </label> <input type="text" ng-model="model" id="input" name="input" ng-pattern="regex" /><br> <hr> input valid? = <code>{{form.input.$valid}}</code><br> model = <code>{{model}}</code> </form> </div> <script src="framework/angular.js"></script> <script src="js/aaa.js"></script> </body> </html>
script.js
angular.module("extendApp",[]) .controller("extendController",function ($scope) { $scope.regex = ‘\\d+‘; });
时间: 2024-10-07 20:45:52