Angular validation function implementation steps
This time I will bring you the steps to implement the Angular verification function. What are the precautions for implementing the Angular verification function? The following is a practical case, let's take a look.
The complete example code is as follows:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>angular验证功能</title> <script src="angular.min.js"></script> <style> input{ display: block; } ul li{ color: red; } </style> <script> angular.module("myapp",[]) .controller("demoC",function($scope){ $scope.datas = [{ id: 10011120, name: "iphoneX", num: 99 }, { id: 10011121, name: "华为mate10", num: 20 }, { id: 10011122, name: "vivoR12", num: 55 } ]; //定义一个数组 $scope.save=function(){ //创建一个存放错误信息数组 $scope.error_val=[]; var reg_id=/^\d{8,8}$/; //只能8位数字 if(!reg_id.test($scope.id)){ $scope.error_val.push("资产编号格式,必须为数字,且长度为8位"); } //资产名称 if($scope.name==undefined||$scope.name==""){ $scope.error_val.push("资产名称不能为空!"); }else{ for(var i in $scope.datas){ if($scope.name==$scope.datas[i].name){ $scope.error_val.push("资产名称已经存在"); break; //结束循环,已经查找到资产名称不合法 } } } //资产数量 var reg_num=/^\d{1,}$/; //只能8位数字 if(!reg_num.test($scope.num)){ $scope.error_val.push("资产编号数量,必须为数字"); }else{ if($scope.num<=0){ $scope.error_val.push("资产编号数量必须大于0"); } } //何时添加进行,何时不添加 if($scope.error_val.length==0){ $scope.datas.push({ id:$scope.id, name:$scope.name, num:$scope.num }); } } }) </script> </head> <body ng-app="myapp" ng-controller="demoC"> <table border="1px solid"> <tr> <td>资产编号</td> <td>资产名称</td> <td>资产数量</td> </tr> <tr ng-repeat="d in datas"> <td>{{d.id}}</td> <td>{{d.name}}</td> <td>{{d.num}}</td> </tr> </table> <p> <form> 资产编号<input ng-model="id" /> 资产名称<input ng-model="name" /> 资产数量<input ng-model="num" /> <p> <ul> <li ng-repeat="e in error_val"> {{e}} </li> </ul> </p> <button ng-click="save()"> 资产录入 </button> </form> </p> </body> </html>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
How to use localstorage and sessionstorage in Vue
The above is the detailed content of Angular validation function implementation steps. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



We usually receive PDF files from the government or other agencies, some with digital signatures. After verifying the signature, we see the SignatureValid message and a green check mark. If the signature is not verified, the validity is unknown. Verifying signatures is important, let’s see how to do it in PDF. How to Verify Signatures in PDF Verifying signatures in PDF format makes it more trustworthy and the document more likely to be accepted. You can verify signatures in PDF documents in the following ways. Open the PDF in Adobe Reader Right-click the signature and select Show Signature Properties Click the Show Signer Certificate button Add the signature to the Trusted Certificates list from the Trust tab Click Verify Signature to complete the verification Let

1. After opening WeChat, click the search icon, enter WeChat team, and click the service below to enter. 2. After entering, click the self-service tool option in the lower left corner. 3. After clicking, in the options above, click the option of unblocking/appealing for auxiliary verification.

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

Angular.js is a freely accessible JavaScript platform for creating dynamic applications. It allows you to express various aspects of your application quickly and clearly by extending the syntax of HTML as a template language. Angular.js provides a range of tools to help you write, update and test your code. Additionally, it provides many features such as routing and form management. This guide will discuss how to install Angular on Ubuntu24. First, you need to install Node.js. Node.js is a JavaScript running environment based on the ChromeV8 engine that allows you to run JavaScript code on the server side. To be in Ub

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

PHP8 is the latest version of PHP, bringing more convenience and functionality to programmers. This version has a special focus on security and performance, and one of the noteworthy new features is the addition of verification and signing capabilities. In this article, we'll take a closer look at these new features and their uses. Verification and signing are very important security concepts in computer science. They are often used to ensure that the data transmitted is complete and authentic. Verification and signatures become even more important when dealing with online transactions and sensitive information because if someone is able to tamper with the data, it could potentially

The default display behavior for components in the Angular framework is not for block-level elements. This design choice promotes encapsulation of component styles and encourages developers to consciously define how each component is displayed. By explicitly setting the CSS property display, the display of Angular components can be fully controlled to achieve the desired layout and responsiveness.
