0
請幫助修復腳本。如何只允許數字?
HTML:
<input type="text" ng-model="phone" id="phoneInput" ng-change="apt.changePhoneInput(phone)">
JS:
var app = angular.module('app', []);
app.controller('Appctrl', Appctrl, '$scope');
function Appctrl($scope){
this.changePhoneInput = function(phone) {
var result = phone;
console.log('phone', phone);
result.replace(/[^+0-9\(\)]/gim,'');
console.log('result', result);
$scope.phone = result;
};
}
我希望允許只輸入數字和後續的符號: '+', '(', ')' ,' - '。但進入之後的任何符號代替不起作用
HTML5 ? 'input type =「number」...>' – fnostro
需要轉義'+'和'-'。你可以使用'\ d'而不是'0-9'。 –
想起來,你可以用'' – fnostro