我写了 ng-pattern 以不以空格开头和结尾。并尝试匹配 $watch 中的双引号。
但它不起作用。ng-pattern 也不起作用
我的 ng 模式是:
<input type="text" class="form-control" ng-model="wifiResult.ssid"
name="ssid"
ng-class="{'inputError' : errorMsg}"
ng-minlength="1"
ng-maxlength="32"
ng-pattern="/^[^\s]+(\s+[^\s]+)*$/"
required >
JS 中的 $watch 是:
$scope.$watch('wifiResult.ssid', function(scope){
var regexToRestrict = /^["]+$/;
if(scope){
var pressChar = scope.slice(-1);
if(pressChar.match(regexToRestrict)){
scope = scope.slice(0,-1); // try to replace " to blank
}
else{
console.log('not matched');
}
}
else{
console.log('no scope');
}
});
有没有其他方法可以做到这一点?
提前致谢 !