Advanced and dynamic input validation with AngularJS
How do I make an advanced and dynamic input validation with angularjs?
What is a advanced and dynamic input validation with angularjs? How do you make a advanced and dynamic input validation with angularjs? This script and codes were developed by Vincenzo on 07 October 2022, Friday.
Advanced and dynamic input validation with AngularJS - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Advanced and dynamic input validation with AngularJS</title> <link rel='stylesheet prefetch' href='https://gitcdn.xyz/repo/angular/bower-material/v0.10.1/angular-material.css'> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ body { display: inline-table; width: 100%; height: 100%;
}
body > div { display: table-cell; vertical-align: middle; text-align: center;
}
body > div > form { width: 44rem; margin: 0 auto; text-align: left;
}
pre { text-align: left; background: #f2f2f2; padding: 1.2rem; border: 1px solid #aaa; border-radius: .3rem;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <div ng-app="TestApp" ng-controller="AppController"> <form name="formTest" flex layout="row"> <md-select ng-model="inputType"> <md-option ng-repeat="input in inputTypes" value="{{input}}">{{input}}</md-option> </md-select> <md-input-container> <label>{{inputType}} input</label> <input type="{{inputType}}" ng-model="value" name="test" required dynamic-input-validator="inputType"/> <div ng-messages="formTest.test.$error"> <!--<div ng-message="parsing">Invalid date</div>--> <div ng-message="required">Value is required</div> <div ng-message="mail">Value is not a valid mail</div> <div ng-message="number">Value is not a valid number</div> <div ng-message="tel">Value is not a valid telephone</div> </div> </md-input-container> </form> <pre>Raw model value: {{value || 'null'}}</pre> <pre>Error: <span ng-repeat="(k,v) in formTest.$error">{{k}}, </span></pre> <!--<pre>Error: {{formTest.$error|json}}</pre>-->
</div> <script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-messages.min.js'></script>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.js'></script>
<script src='https://gitcdn.xyz/repo/angular/bower-material/v0.10.1/angular-material.js'></script> <script src="js/index.js"></script>
</body>
</html>
Advanced and dynamic input validation with AngularJS - Script Codes CSS Codes
body { display: inline-table; width: 100%; height: 100%;
}
body > div { display: table-cell; vertical-align: middle; text-align: center;
}
body > div > form { width: 44rem; margin: 0 auto; text-align: left;
}
pre { text-align: left; background: #f2f2f2; padding: 1.2rem; border: 1px solid #aaa; border-radius: .3rem;
}
Advanced and dynamic input validation with AngularJS - Script Codes JS Codes
var testApp = angular.module('TestApp', ['ngMaterial', 'ngMessages']).directive('dynamicInputValidator', function () { return { restrict: 'A', require: 'ngModel', scope: { ngModel: '=', dynamicInputValidator: '=' }, link: function (scope, elm, attrs, ctrl) { scope.$watch("dynamicInputValidator", function() { ctrl.$validate(); }); /*ctrl.$formatters.push(function (value) { return value; });*/ /*ctrl.$parsers.push(function (newValue) { return newValue; });*/ var mailRe = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/ ; var numberRe = /^[+-]?(?=.)(?:\d+,)*\d*(?:\.\d+)?$/; var telRe = /^\+?[ .-\d]+(-\d+)*(\d)$/; ctrl.$validators.mail = function (modelValue, viewValue) { return scope.dynamicInputValidator=="email" ? mailRe.test(viewValue) : true; }; ctrl.$validators.number = function (modelValue, viewValue) { return scope.dynamicInputValidator=="number" ? numberRe.test(viewValue) : true; }; ctrl.$validators.tel = function (modelValue, viewValue) { return scope.dynamicInputValidator=="tel" ? telRe.test(viewValue) : true; }; } } });
testApp.controller('AppController', ['$scope', function ($scope) { $scope.inputTypes = ['text', 'email', 'number', 'tel']; $scope.inputType = $scope.inputTypes[0]; $scope.value = "";
}]);
Developer | Vincenzo |
Username | vncnz |
Uploaded | October 07, 2022 |
Rating | 3 |
Size | 3,343 Kb |
Views | 28,336 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Search text highlight example with material.angular | 2,602 Kb |
Tintometer | 3,302 Kb |
Pure CSS cut corner box test | 2,981 Kb |
Swiping Cards | 5,691 Kb |
Private Test | 4,434 Kb |
Simple Date input with VueJS 2 | 10,802 Kb |
Simple tags input with VueJS | 8,463 Kb |
Elegant layout with elastic menu animation | 6,245 Kb |
AngularJS DateTimePicker concept | 4,393 Kb |
Square box with hover effect | 2,265 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
JavaScript constructors | Simboonlong | 2,415 Kb |
Twitch Live Channels | Inkblotty | 4,956 Kb |
Sign Up Form | Sicontis | 5,272 Kb |
Fullscreen Parallax | Bassta | 3,313 Kb |
CSS Tooltips | Darylldoyle | 2,599 Kb |
ABVI Menu Discarded | Overdrivemachines | 3,607 Kb |
Matrix | Stathisnikolaidis | 1,922 Kb |
Loading animation | Codeams | 2,408 Kb |
Calendar | Miroot | 2,033 Kb |
Drill-down Map | Good886 | 8,484 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!