我正在使用 angularjs 在文本框上进行客户端验证,我只需要输入字母数字字符即可。如果文本框留空或输入了非字母数字字符,则提交表单会向 JS 发送所需的“false”,但问题是它本身没有传递非字母数字字符(在范围内)。
JSP 文件:
<form name="addressForm" method="post"
ng-submit="submitform(addressForm.$valid)" novalidate>
..
<input ng-model="address" type="text"
**ng-pattern**="/^[a-zA-Z0-9 ]*$/" required="true"/>
JS文件:
$scope.submitform= function(isValid){
var inputAddr = $scope.address;
alert(inputAddr); //coming as undefined
...
现在,当我在 jsp 中的输入框“地址”中输入一个字母数字字符时,它在 JS 中警告它时给了我未定义的定义(可能是因为过滤字符为非字母数字的模式)。如果我删除 ng-pattern,它会通过 submitForm 传递“真”,就好像每个输入都是“预期的”。我想访问 $scope.address 的原因是检查和评估并显示“空”和“非字母数字”验证的不同错误消息。
任何帮助表示赞赏!