ng-pattern需要一个正则表达式。
从Angular的文档中有关
ng-pattern:
如果该值与
RegExp模式表达式不匹配,则设置模式验证错误键。期望值/regexp/用于内联模式或regexp定义为作用域表达式的模式。
换句话说,您可以在控制器中创建一个RegExp:
$scope.pattern = new RegExp(patternFromServer);
并使用它:
<input ng-model="foo" ng-pattern="pattern">

ng-pattern需要一个正则表达式。
从Angular的文档中有关
ng-pattern:
如果该值与
RegExp模式表达式不匹配,则设置模式验证错误键。期望值/regexp/用于内联模式或regexp定义为作用域表达式的模式。
换句话说,您可以在控制器中创建一个RegExp:
$scope.pattern = new RegExp(patternFromServer);
并使用它:
<input ng-model="foo" ng-pattern="pattern">