【发布时间】:2014-09-30 08:03:22
【问题描述】:
我很想检测字符串与正则表达式匹配的位置,但这似乎在模糊时失败。请看这个plunkr。
这是 js:
var endsWithPipeOrSpace = /\s+$|\|$/g;
$scope.inputGetFocus = function() {
$scope.msg = "input gained focus"
if (endsWithPipeOrSpace.test($scope.newquery)) {
$scope.msg += " string match";
} else {
$scope.msg += " string doesn't match";
}
}
$scope.inputLostFocus = function() {
$scope.msg = "input has lost focus"
if (endsWithPipeOrSpace.test($scope.newquery)) {
$scope.msg += " string match";
} else {
$scope.msg += " string doesn't match";
}
}
$scope.newQueryModified = function() {
$scope.msg = "input modified"
if (endsWithPipeOrSpace.test($scope.newquery)) {
$scope.msg += " string match";
} else {
$scope.msg += " string doesn't match";
}
}
这是 HTML:
请注意我声明 ng-trim="false"
<input type="text" class="form-control"
id="newquery" ng-model="newquery"
placeholder="Enter your query"
autofocus required autocomplete="off"
ng-change="newQueryModified()"
ng-trim="false"
ng-focus="inputGetFocus()"
ng-blur="inputLostFocus()">
【问题讨论】:
标签: regex angularjs input trim onblur