简体   繁体   English

检查文本框中的整个字符串值是零(0)还是特殊字符

[英]Check if the entire String value in Textbox is zero(0) or of special characters

I have a Textbox in which i'm getting the input of type text having the length 20, I have a scenario in which i have to evaluate whether the entire string input from the client is not zero or any special characters 我有一个文本框,在其中我得到长度为20的文本类型的输入,在这种情况下,我必须评估从客户端输入的整个字符串是否为零或任何特殊字符

eg: 00000000000,00000,00,00000,00000/-/--,/-/-----////,aBadf-018---///sdf484,AA///---000 all these above inputs are invalid, the string could be of any length in between 2 to 20, 例如: 00000000000,00000,00,00000,00000/-/--,/-/-----////,aBadf-018---///sdf484,AA///---000全部以上这些输入无效,字符串的长度可以在2到20之间,

i have restricted the user to input other special characters other than hyphen and dash, regex used over here to invalidate the value other than hyphen and dash are as follows : 我已限制用户输入除连字符和破折号以外的其他特殊字符,此处使用的正则表达式使除连字符和破折号以外的值无效:

" /[^a-zA-Z0-9/-]/g "

<input type="text" name="consumer_number" maxlength="25" ng-disabled="!form_data[selectedTab].electrici‌​ty.check" alpha-numeric-with-slash-and-hyphen data-ng-model="form_data[selectedTab].electric‌​ity.unique_no" class="input-field" data-ng-blur="validateElecConsumer(selectedTab‌​)" ng-class="{true:'invalid-field',false:''}[form‌​_data[selectedTab].e‌​lectricity.check && form_data[selectedTab].invalid.electricity]" required /> 

Now my concern is how could i display a message right upfront that whatever the input the user have provided is invalid. 现在,我担心的是,我如何才能立即显示一条消息,说明用户提供的任何输入均无效。

This may help: 这可能会有所帮助:

 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM