<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8" />
<title>My AngularJS App</title>
</head>
<body ng-controller="stageController">
<div id="main">
<h1>Form Validation</h1>
<div id="more">
<p>Read <a href="http://blog.brunoscopelliti.com/form-validation-the-angularjs-way"
title="Form Validation: The AngularJS Way">Form Validation: The AngularJS Way</a>.</p>
</div>
<p class="intro">This example shows how validate forms thanks to AngularJS.
<br/>AngularJS performs a client side validation; the main objective of client
side validation is not to ensure the security of the data system, but it
is to help user complete the submission of the form. Because the client
side validation could be easily bypassed, it is important to replicate
the validation and sanitization of the data also server side.</p>
<form
name="myForm" novalidate ng-submit="submitForm();">
<h2>Form submit:</h2>
<p>Note that I didn't specify an <em>action</em> property for the form. That's
because AngularJS prevents the default action (form submission to the server)
unless the <form> element has an action attribute specified. I use
the <a href="http://docs.angularjs.org/api/ng.directive:ngSubmit" title="AngularJS api: ngSubmit"
target="_blank">ngSubmit</a> directive to specify a behaviour to apply when
the form is submitted.</p>
<h2>AngularJS novalidate:</h2>
<p>On the form is used the directive <b>novalidate</b>, to disable browser's
native form validation.</p>
<h2>AngularJS built-in directive for form validation:</h2>
...
'use strict';
// Declare app level module which depends on filters, and services
angular.module('myApp', []);
/* Controllers */
function stageController($scope) {
$scope.username1 = 'Peter Parker';
$scope.email1 = '[email protected]';
$scope.username2 = 'Clark Kent';
$scope.submitForm = function () {
console.info("Here I should implement the logic to send a request to the server.");
}
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.