Skip to main content

Angular Js Form Validation

<!DOCTYPE html>
<html>
<script src="angular.min.js"></script>
<body>

<h2>Validation Example</h2>

<form ng-app="myApp" ng-controller="validateCtrl"
name="myForm" novalidate>

<p>Username:<br>
<input type="text" name="user" ng-model="user" required>
<span style="color:red" ng-show="myForm.user.$dirty && myForm.user.$invalid">
<span ng-show="myForm.user.$error.required">Username is required.</span>
</span>
</p>

<p>Email:<br>
<input type="email" name="email" ng-model="email" required>
<span style="color:red" ng-show="myForm.email.$dirty && myForm.email.$invalid">
<span ng-show="myForm.email.$error.required">Email is required.</span>
<span ng-show="myForm.email.$error.email">Invalid email address.</span>
</span>
</p>

<p>
<input type="submit" ng-disabled="myForm.user.$dirty && myForm.user.$invalid ||
myForm.email.$dirty && myForm.email.$invalid">
</p>

</form>

<script>
var app = angular.module('myApp', []);
app.controller('validateCtrl', function($scope) {
    $scope.user = 'John Doe';
    $scope.email = 'john.doe@gmail.com';
});
</script>

</body>
</html>

Comments

Popular posts from this blog

IDB HTML MCQ

Questions: 1. A webpage displays a picture. What tag was used to display that picture? a. picture b. image c. img d. src 2. <b> tag makes the enclosed text bold. What is other tag to make text bold? a. <strong> b. <dar> c. <black> d. <emp> 3. Tags and test that are not directly displayed on the page are written in _____ section. a. <html> b. <head> c. <title> d. <body> 4. Which tag inserts a line horizontally on your web page? a. <hr> b. <line> c. <line direction=”horizontal”> d. <tr> 5. What should be the first tag in any HTML document? a. <head> b. <title> c. <html> d. <document> 6. Which tag allows you to add a row in a table? a. <td> and </td> b. <cr> and </cr> c. <th> and </th> d. <tr> and </tr> 7. How can you make a bulleted list? a. <list> b. <nl> c. <ul> d. <ol> 8. Ho

Database Connection with PHP PDO MYSQL

PDO Connection MYSQLI // Create Connection with Pdo\ $dsn = "mysql:host=localhost; dbname=test;"; $db_user = "root"; $db_password = ""; try{     $conn = new PDO("$dsn", "$db_user","$db_password");    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     // $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     echo "Connected"; }catch(PDOException $a){     echo "Connection Failed". $a->getMessage(); }