输入文本字段(移动应用程序),不允许用户使用angularjs输入数值

时间:2015-11-25 07:11:25

标签: javascript angularjs jquery-mobile ionic-framework

<input type="text"  
       ng-model="emp.eedKey007" 
       ng-keypress="nonNumericInput($event)" >

移动应用程序的输入文本字段(应用程序使用ionic和angularjs),它与控制器中的$ scope.emp.eedKey007映射。 我想使这个文本字段非数字。如果用户想插入任何数字值,他将无法输入文本字段(MOBILE)

$scope.nonNumericInput = function ($event) {
    console.log("key presed");
    $scope.showFixAlert = function() {
        var alertPopup = $ionicPopup.alert({
            title: $translate('Info'),
            template: $translate('Invalid Input ...')
        });
    };
    var charCode = $event.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {  
        console.log("Character is pressed"); 
    } else {
        $scope.showFixAlert();
        /**/ what code should i need to use here so that i can restrict numeric value inserted in text field.** 
       // in below code i try to replace the numeric  character with blank character. which is assigned in eedKey007 but its not working correctly . I can't blank the textfield on numeric value insertion.
        var StringLang = $scope.emp.eedKey007;
        $scope.emp.eedKey007 = StringLang.replace(StringLang.slice(-1),''); 
    }
}

1 个答案:

答案 0 :(得分:0)

使用$ event.preventDefault();在你的情况下。它会阻止将数值输入到输入框。