{"id":65,"date":"2024-12-06T07:16:32","date_gmt":"2024-12-06T07:16:32","guid":{"rendered":"https:\/\/alpeshconnect.in\/blog\/?p=65"},"modified":"2024-12-06T07:16:32","modified_gmt":"2024-12-06T07:16:32","slug":"form-validation-using-angular-js","status":"publish","type":"post","link":"https:\/\/alpeshconnect.in\/blog\/2024\/12\/06\/form-validation-using-angular-js\/","title":{"rendered":"Form Validation using Angular JS"},"content":{"rendered":"\n<p>Angular JS which accepts and validate student Name , Email and Mobile from the user<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"278\" src=\"https:\/\/alpeshconnect.in\/blog\/wp-content\/uploads\/2024\/12\/image-10-1024x278.png\" alt=\"Form Validation using Angular JS\" class=\"wp-image-66\" title=\"Form Validation using Angular JS\" srcset=\"https:\/\/alpeshconnect.in\/blog\/wp-content\/uploads\/2024\/12\/image-10-1024x278.png 1024w, https:\/\/alpeshconnect.in\/blog\/wp-content\/uploads\/2024\/12\/image-10-300x81.png 300w, https:\/\/alpeshconnect.in\/blog\/wp-content\/uploads\/2024\/12\/image-10-768x208.png 768w, https:\/\/alpeshconnect.in\/blog\/wp-content\/uploads\/2024\/12\/image-10.png 1176w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\n&lt;html lang=\"en\" ng-app=\"studentApp\">\n&lt;head>\n    &lt;meta charset=\"UTF-8\">\n    &lt;title>Student Form&lt;\/title>\n    &lt;link rel=\"stylesheet\" href=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.4.1\/css\/bootstrap.min.css\">\n&lt;\/head>\n&lt;body ng-controller=\"StudentController\">\n\n&lt;div class=\"container\">\n    &lt;h2>Student Form&lt;\/h2>\n    &lt;form name=\"studentForm\" ng-submit=\"submitForm(studentForm.$valid)\" novalidate>\n\n        &lt;!-- Name -->\n        &lt;div class=\"form-group\" ng-class=\"{'has-error': studentForm.name.$touched &amp;&amp; studentForm.name.$invalid}\">\n            &lt;label for=\"name\">Name:&lt;\/label>\n            &lt;input type=\"text\" class=\"form-control\" id=\"name\" name=\"name\" ng-model=\"student.name\" required>\n            &lt;span class=\"help-block\" ng-show=\"studentForm.name.$touched &amp;&amp; studentForm.name.$error.required\">Name is required.&lt;\/span>\n        &lt;\/div>\n\n        &lt;!-- Email -->\n        &lt;div class=\"form-group\" ng-class=\"{'has-error': studentForm.email.$touched &amp;&amp; studentForm.email.$invalid}\">\n            &lt;label for=\"email\">Email:&lt;\/label>\n            &lt;input type=\"email\" class=\"form-control\" id=\"email\" name=\"email\" ng-model=\"student.email\" required>\n            &lt;span class=\"help-block\" ng-show=\"studentForm.email.$touched &amp;&amp; studentForm.email.$error.required\">Email is required.&lt;\/span>\n            &lt;span class=\"help-block\" ng-show=\"studentForm.email.$touched &amp;&amp; studentForm.email.$error.email\">Invalid email address.&lt;\/span>\n        &lt;\/div>\n\n        &lt;!-- Mobile Number -->\n        &lt;div class=\"form-group\" ng-class=\"{'has-error': studentForm.mobile.$touched &amp;&amp; studentForm.mobile.$invalid}\">\n            &lt;label for=\"mobile\">Mobile No:&lt;\/label>\n            &lt;input type=\"text\" class=\"form-control\" id=\"mobile\" name=\"mobile\" ng-model=\"student.mobile\" ng-pattern=\"\/^\\d{10}$\/\" required>\n            &lt;span class=\"help-block\" ng-show=\"studentForm.mobile.$touched &amp;&amp; studentForm.mobile.$error.required\">Mobile number is required.&lt;\/span>\n            &lt;span class=\"help-block\" ng-show=\"studentForm.mobile.$touched &amp;&amp; studentForm.mobile.$error.pattern\">Mobile number must be 10 digits.&lt;\/span>\n        &lt;\/div>\n\n        &lt;!-- Submit Button -->\n        &lt;button type=\"submit\" class=\"btn btn-primary\" ng-disabled=\"studentForm.$invalid\">Submit&lt;\/button>\n\n    &lt;\/form>\n&lt;\/div>\n\n&lt;!-- Include AngularJS -->\n&lt;script src=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/angularjs\/1.8.2\/angular.min.js\">&lt;\/script>\n&lt;script>\n    var app = angular.module('studentApp', &#91;]);\n\n    app.controller('StudentController', function($scope) {\n        $scope.student = {};\n\n        $scope.submitForm = function(isValid) {\n            if (isValid) {\n                alert('Form Submitted Successfully!');\n                console.log($scope.student);\n            } else {\n                alert('Please fill out the form correctly.');\n            }\n        };\n    });\n&lt;\/script>\n\n&lt;\/body>\n&lt;\/html>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Angular JS which accepts and validate student Name , Email and Mobile from the user<\/p>\n","protected":false},"author":1,"featured_media":41,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,3],"tags":[8,9],"class_list":["post-65","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-advanced-web-designing","category-bca","tag-advanced-web-designing","tag-angular-js"],"_links":{"self":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/65","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":2,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":68,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/posts\/65\/revisions\/68"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media\/41"}],"wp:attachment":[{"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alpeshconnect.in\/blog\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}