Angularjs Form Validation Example Tutorial From Scratch

Today, We want to share with you Angularjs Form Validation Example Tutorial From Scratch.In this post we will show you Angular Forms and Validation: Step By Step Example, hear for AngularJS Form Validation With ngMessages we will give you demo and example for implement.In this post, we will learn about AngularJS Form Validation: TextBox, Button Click with an example.

Angularjs Form Validation Example Tutorial From Scratch

There are the Following The simple About Angularjs Form Validation Example Tutorial From Scratch Full Information With Example and source code.

As I will cover this Post with live Working example to develop Angular Reactive Forms: trigger validation on submit, so the some major files and Directory structures for this example is following below.

  • index.php
  • app.js

angularjs form validation error message

Create index.php

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.php.

Read Also:  Laravel Helper Functions with Examples

<!DOCTYPE html>
<html lang="en" ng-app="membersApp">
<head>
    <meta charset="utf-8">
    <title>Angularjs Form Validation Example Tutorial From Scratch</title>
    <!-- Latest Version of the bootstrap.min.css -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <!-- angular.min.js -->
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
    <style type="text/css">
      .liveErrorTxt{
        color:red;
      }
    </style>
</head>
<body ng-controller="membersController">
<div class="pakainfo container">
    <h1 class="page-header">Angularjs Form Validation Example Tutorial From Scratch</h1>
    <div class="pakainfo col-md-6 col-md-offset-3">
      <div class="pakainfo login-panel panel panel-success">
          <div class="panel-heading">
              <h3 class="panel-title"> Validation Form</h3>
          </div>
        <div class="panel-body">
            <form role="form" name="memberForm" novalidate>
              <fieldset>
                <div class="lst form-group">
                    <input type="text" class="memberfield form-control" name="memfirstname" placeholder="MemberName" ng-minlength="10" ng-maxlength="30" ng-pattern="/^[a-zA-Z0-9_]*$/" ng-model="member.memfirstname" required autofocus>
                    <div class="liveErrorTxt" ng-show="memberForm.memfirstname.$dirty && memberForm.memfirstname.$invalid">
                      <span ng-show="memberForm.memfirstname.$error.required">MemberName is required</span>
                      <span ng-show="memberForm.memfirstname.$error.minlength">MemberName must contain atleast 10 characters</span>
                      <span ng-show="memberForm.memfirstname.$error.maxlength">MemberName know not be greater than 30 characters</span>
                      <span ng-show="memberForm.memfirstname.$error.pattern && !memberForm.memfirstname.$error.minlength && !memberForm.memfirstname.$error.maxlength">Only letters, numbers and underscore allowed</span>
                    </div>
                </div>
                <div class="lst form-group">
                    <input type="password" class="memberfield form-control" name="password" placeholder="Password" ng-model="member.password" required>
                    <div class="liveErrorTxt" ng-show="memberForm.password.$dirty && memberForm.password.$invalid">
                      <span ng-show="memberForm.password.$error.required">Password is required</span>
                    </div>
                </div>
                <div class="lst form-group">
                    <input type="password" class="memberfield form-control" name="membersrespass" placeholder="Member Re-type Password" ng-model="member.membersrespass" required>
                    <div class="liveErrorTxt" ng-show="memberForm.membersrespass.$dirty && memberForm.membersrespass.$invalid || memberForm.membersrespass.$dirty && member.membersrespass != member.password">
                      <span ng-show="memberForm.membersrespass.$error.required">Re-type password is required</span>
                      <span ng-show="!memberForm.membersrespass.$error.required && member.membersrespass != member.password">Password did not match</span>
                    </div>
                </div>
                <div class="lst form-group">
                    <input  type="email" class="memberfield form-control" name="email" placeholder="Member Email" ng-model="member.email" required>
                    <div class="liveErrorTxt" ng-show="memberForm.email.$dirty && memberForm.email.$invalid">
                      <span ng-show="memberForm.email.$error.required">Member Email is required</span>
                      <span ng-show="memberForm.email.$error.email">Invalid email format</span>
                    </div>
                </div>
                <div class="lst form-group">
                    <input type="url" class="memberfield form-control" name="url" placeholder="Member Website" ng-model="member.website" required>
                    <div class="liveErrorTxt" ng-show="memberForm.url.$dirty && memberForm.url.$invalid">
                      <span ng-show="memberForm.url.$error.required">Member Website is required</span>
                      <span ng-show="memberForm.url.$error.url">Input a valid Member website</span>
                    </div>
                </div>
                <div class="lst form-group">
                    <input type="text" class="memberfield form-control" name="memberfirstname" placeholder="Member Firstname" ng-model="member.memberfirstname" required>
                    <div class="liveErrorTxt" ng-show="memberForm.memberfirstname.$dirty && memberForm.memberfirstname.$invalid">
                      <span ng-show="memberForm.memberfirstname.$error.required">Firstname is required</span>
                    </div>
                </div>
                <div class="lst form-group">
                    <input  type="text" class="memberfield form-control" name="memberlastname" placeholder="Member Lastname" ng-model="member.memberlastname" required>
                    <div class="liveErrorTxt" ng-show="memberForm.memberlastname.$dirty && memberForm.memberlastname.$invalid">
                      <span ng-show="memberForm.memberlastname.$error.required">Member Lastname is required</span>
                    </div>
                </div>
                <button type="button" class="btn btn-lg btn-success btn-block" ng-disabled="memberForm.$invalid || member.membersrespass != member.password" ng-click="submit()"><span class="live glyphicon glyphicon-check"></span> Validate</button>
              </fieldset>
            </form>
        </div>
      </div>
    <div class="alert alert-success" ng-show="valid">
      <button type="button" class="live close" ng-click="close()"><span aria-hidden="true">×</span></button>
      <span class="live glyphicon glyphicon-check"></span>Check Form Validated
    </div>
  </div>
</div>
<script src="app.js"></script>
</body>
</html>

AngularJS Script Source Code

Create app.js file

var membersApp = angular.module('membersApp', []);
membersApp.controller('membersController', function($scope){
	$scope.valid = false;
	$scope.submit = function(){
		$scope.valid = true;
	}
	$scope.close = function(){
		$scope.valid = false;
	}
});

Angularjs Form Validation Example Tutorial – Source code

Angularjs Form Validation Example Tutorial From Scratch - code
Angularjs Form Validation Example Tutorial From Scratch – code
Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  jQuery Ajax Image Upload without Page Refresh using PHP

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Angularjs Form Validation Example Tutorial From Scratch.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.