Angular: Empty Fiddle

http://angularjs.org/

by malamine_kebe

HTML

<script src=" https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js "></script>
    <div ng-app="myApp">
      <form name="formTemplate" novalidate>
        <input id="email1" type="email" ng-model="currentForm.email1" name="email1" required>
        <span ng-show="formTemplate.email1.$error.required && formTemplate.email1.$dirty">required</span>
        <span ng-show="!formTemplate.email1.$error.required && formTemplate.email1.$error.email1 && formTemplate.email1.$dirty">invalid email</span>  
        <input id="email2" type="email" name="email2" ng-model="currentForm.email2" same-email required>
        <span ng-show="formTemplate.email2.$error.required && formTemplate.email2.$dirty">Please confirm your email.</span>
        <span ng-show="!formTemplate.email2.$error.required && formTemplate.email2.$error.noMatch && formTemplate.email1.$dirty">Emails do not match.</span>
      </form>
    </div>

CSS

.ng-invalid.ng-dirty{
	border-color: #FA787E;
}

.ng-valid.ng-dirty{
	border-color: #78FA89;
}

JavaScript

var app = angular.module('myApp', ['UserValidation']);


angular.module('UserValidation', []).directive('sameEmail', function () {
    return {
        require: 'ngModel',
        link: function (scope, elm, attrs, ctrl) {
            ctrl.$parsers.unshift(function (viewValue, $scope) {
                var noMatch = viewValue != scope.formTemplate.email1.$viewValue;
                ctrl.$setValidity('noMatch', !noMatch)
            })
        }
    }
})