【发布时间】:2016-05-16 15:00:34
【问题描述】:
我在 android studio 中开发了 phonegap 应用程序。
我有一个必须允许 abc 字符、引号和双引号的输入字段。
想要的html代码:
<input placeholder="last name" type="text" ng-model="currentUser.LastName"
ng-pattern='/^([A-Za-z\"\' ]){1,45}$/'
required
class="form-control"/>
但我有一个问题 - 正则表达式中的引号关闭了整个正则表达式。
我能做什么:
ng-pattern='/^([A-Za-z\" ]){1,45}$/'
或
ng-pattern="/^([A-Za-z\' ]){1,45}$/"
但我也找不到包含引号和双引号的方法。
我试过了:
范围内:
$scope.regex=/^([A-Za-z\"\' ]){1,45}$/;
在html页面中:
<input placeholder="last name" type="text" ng-model="currentUser.LastName" name="userLastName1"
ng-pattern='{{regex}}'
required
class="form-control"/>
也没有用(我的编辑器是android studio,也许其他编辑器更好?)。
有没有办法在一个正则表达式中同时包含引号和双引号?
【问题讨论】:
-
According to the documentation 你不需要插入范围变量。您应该能够将它作为
$scope.regex=/^([A-Za-z\"\' ]){1,45}$/;放入您的控制器中,然后在您的模板中使用它作为ng-pattern='regex' -
我刚刚编辑过,有问题,实际代码是对的但它不起作用。
-
it did not work是什么意思?
标签: javascript android angularjs regex