[英]Check if the entire String value in Textbox is zero(0) or of special characters
我有一個文本框,在其中我得到長度為20的文本類型的輸入,在這種情況下,我必須評估從客戶端輸入的整個字符串是否為零或任何特殊字符
例如: 00000000000,00000,00,00000,00000/-/--,/-/-----////,aBadf-018---///sdf484,AA///---000
全部以上這些輸入無效,字符串的長度可以在2到20之間,
我已限制用戶輸入除連字符和破折號以外的其他特殊字符,此處使用的正則表達式使除連字符和破折號以外的值無效:
" /[^a-zA-Z0-9/-]/g "
<input type="text" name="consumer_number" maxlength="25" ng-disabled="!form_data[selectedTab].electricity.check" alpha-numeric-with-slash-and-hyphen data-ng-model="form_data[selectedTab].electricity.unique_no" class="input-field" data-ng-blur="validateElecConsumer(selectedTab)" ng-class="{true:'invalid-field',false:''}[form_data[selectedTab].electricity.check && form_data[selectedTab].invalid.electricity]" required />
現在,我擔心的是,我如何才能立即顯示一條消息,說明用戶提供的任何輸入均無效。
這可能會有所幫助:
var app = angular.module("app", []); app.controller("MyController", function($scope){ $scope.inputtext = ""; $scope.onSubmit = function() { var val = $scope.inputtext; if (val.length < 2 || val.length > 20 || !val.match(/[^a-zA-Z0-9/-]/g)) { alert("Unacceptable"); } else { alert("you pass"); } }; });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="app" ng-controller="MyController"> <input maxlength="20" id="inputtext" ng-model="inputtext" type="text"/> <button id="submitbutton" ng-click="onSubmit()" type="text">submit</button> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.