I have written ng-pattern for not to start and end with space. And trying to match double quotation in $watch.
But it is not working. ng-pattern is also not working
my ng-pattern is:
<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 >
$watch in JS is:
$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');
}
});
Is there any other way to do this?
Thanks in advance !