简体   繁体   English

Angular JS依赖表单字段验证

[英]Angular JS Dependent Form Field Validations

I have to implement validation in angular js. 我必须在angular js中实现验证。 The requirement is, there is a form containing an input field which can contain only 9 digits.Below that input field there are three radio buttons. 要求是有一个包含一个输入字段的表格,该字段只能包含9位数字,在该输入字段下方有三个单选按钮。 Now, upon form submission, i have to check whether the input field is valid(containing 9 digits) if the user has entered data into the input field and also if the user has not entered any data into the input field, a validation message should appear instructing the user to select any one of the below options(radio buttons).Since am a novice in angularjs , can someone tell me how should i implement this in angularjs. 现在,在提交表单后,我必须检查输入字段是否有效(包含9位数字),如果用户已经在输入字段中输入了数据,并且如果用户没有在输入字段中输入任何数据,则验证消息应该出现时,指示用户选择以下任一选项(单选按钮)。由于我是angularjs的新手,所以有人可以告诉我如何在angularjs中实现此功能。

Example Code : 示例代码:

<input type="text" inputmode="numeric" id="someNumber" name="someNumber" ng-maxlength="9" ng-model="vm.someFileNumber">
If you don't have SomeNumber, then please answer the following
<input type="radio" ng-model="vm.option1">
<input type="radio" ng-model="vm.option2">
<input type="radio" ng-model="vm.option3">

您需要为单选按钮设置通用名称,并将ng-required =“!vm.someFileNumber”属性设置为其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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