Example of form validation in ANGULARJS messages

Source: Internet
Author: User
Tags control label


Earlier I demonstrated the angular form validation example: Angularjs's Form validation example, in fact, we can use angular provided module messages for easier form validation,



<html> <head> <link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"> <script src="//cdn.bootcss.com/angular.js/1.4.4/angular.js"></script> <script src="angular-messages.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> var app = angular.module('app', ['ngMessages']); app.controller('Ctrl',function () { } </script> </head> <style type="text/css"> .error{color: indianred;} .success{color: green;} </style> <body ng-app='app'> <div ng-controller="Ctrl"> <form class="form-horizontal" name="form" role="form"> <div class="form-group"> < label for = "user" class = "col-sm-2 control label" > user name < / label > <div class="col-sm-5"> <input type="text" ng-model="user.username" name="user"  ng-pattern="/^[a-zA-Z]\w{2,10}[a-zA-Z\d]$/" class="form-control" required="required"> </div> <div ng-messages="form.user.$error"> < div ng message = "required" > required items < / div > < div ng message = "pattern" > non conformance < / div > </div> </div> < button ng disabled = "form. $invalid" > submit < / button > </form> </div> </body> </html>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.