2

我有一个看起来像的输入字段

 <input class="inputMargin urlInputWidth" type="text" size="40" name="url" ng-model="user.customerId" maxlength="250" ng-pattern="/sftp://.+/" />

它工作正常并按预期显示验证。我只是想将这种模式移动到 angularjs 的范围内以获得更整洁的形式。我已经尝试过使用这种语法:$scope.sftpValidate="/sftp://.+/";ng-pattern="sftpValidate". 但这根本不能验证模式。我试图给 as$scope.sftpValidate=/sftp://.+/;$scope.sftpValidate=sftp://.+;。但这些显示语法错误。我在哪里失踪?

4

1 回答 1

3

请参阅JSBin

看法:

<input class="inputMargin urlInputWidth" type="text" size="40" name="url" ng-model="user.customerId" maxlength="250" ng-pattern="regex " />

JS

$scope.regex = /sftp://.+/;

JS由短信更新:

$scope.regex = /sftp:\/\/.+/;
于 2014-06-19T09:18:56.657 回答