Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs AngularNG模式指令的意外行为_Angularjs_Angularjs Directive - Fatal编程技术网

Angularjs AngularNG模式指令的意外行为

Angularjs AngularNG模式指令的意外行为,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我想使用ng模式验证文本字段。该字段应接受除空格以外的所有字符 我编写了以下html: <input name="username" ng-model="username" ng-pattern='/^[\S]+$/' type="text"> 起始空格和尾随空格将被忽略。它将不带引号的字符串d计算为有效 有什么问题? 提前谢谢 我认为这与你的模式有关,请按以下方式尝试 /^[\S]*$/ 我认为您无法从输入中删除空间包装器 您可以尝试使用ng trim='false'>版本1.

我想使用ng模式验证文本字段。该字段应接受除空格以外的所有字符

我编写了以下html:

<input name="username" ng-model="username" ng-pattern='/^[\S]+$/' type="text">
起始空格和尾随空格将被忽略。它将不带引号的字符串d计算为有效

有什么问题?
提前谢谢

我认为这与你的模式有关,请按以下方式尝试

/^[\S]*$/

我认为您无法从输入中删除空间包装器

您可以尝试使用ng trim='false'>版本1.1.1

防止用户输入空白的其他替代方法

HTML

/^[\S]*$/
<input ng-model='name' ng-trim='false' />
var app = angular.module('angularjs-starter', []);

 app.controller('MainCtrl', function($scope,$timeout) {
 $scope.name = 'World';
 $scope.$watch('name', function() {
     $scope.name = $scope.name.replace(/\s+/g,'');
  });
});