0% found this document useful (0 votes)
6 views

JavaScript Val

Uploaded by

vaibhavigirkar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

JavaScript Val

Uploaded by

vaibhavigirkar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

**********************************************************************************

EXPERIMENT NO:-03
Roll NO.:-

BATCH:- SUB:-WC-LAB BRANCH:-TE(AIML)

**********************************************************************************

Aim: Write a JavaScript program for validating REGISTRATION FORM.


Software Required: Visual Studio Code, Mozilla Firefox.
Theory:
Form validation is the process of ensuring that the data submitted through a web form meets the
required standards before it is processed or stored. The primary purpose of form validation is to
improve data accuracy, enhance security, and provide a better user experience. By validating the
data, we can prevent common issues such as incomplete submissions, incorrect data formats, and
malicious inputs.

1. Client-Side Validation:

 Definition: This type of validation occurs in the user’s browser before the data is sent to the
server. JavaScript is commonly used to perform client-side validation.

 Purpose: It provides immediate feedback to the user, allowing them to correct errors in real-
time without needing to reload the page.

 Examples: Checking if required fields are filled, verifying email format, and ensuring
password strength.

JavaScript is a powerful tool for client-side form validation, offering several key benefits:

1. Speed and User Experience Improvements:

 Instant Feedback: JavaScript allows for real-time validation, providing users with immediate
feedback as they fill out the form. This reduces frustration by highlighting errors instantly and
guiding users to correct them without submitting the form multiple times.

 Enhanced Interaction: By validating form data on the client side, users experience smoother
interactions, leading to higher satisfaction and engagement.

2. Real-Time Feedback:

 Error Highlighting: JavaScript can dynamically highlight erroneous fields, display helpful error
messages, and even suggest corrections. This real-time interaction helps users understand
what needs to be fixed and how.

 Interactive Elements: Using JavaScript, you can create more interactive form elements, such
as showing/hiding sections based on user input, enhancing the overall usability of the form.

3. Reducing Server Load:

 Efficiency: By catching errors on the client side, JavaScript reduces the number of incorrect
form submissions sent to the server. This decreases server load and optimizes the processing
of valid data.

 Resource Management: Validating forms on the client side ensures that only clean and
properly formatted data reaches the server, making better use of server resources and
improving performance.
Program:
<html>

<head>

<title>form validation</title>

</head>

<body>

<script>

function data1()

var a = document.getElementById("n1").value;

var b = document.getElementById("n2").value;

var c = document.getElementById("n3").value;

var d = document.getElementById("n4").value;

var e=document.getElementById("n5").value;

if(a==""||b==""||c==""||d==""||e=="")

alert("All field are mandatory");

else if(b.length<10||b.length>10)

alert("Number should be 10 digit");

else if(isNaN(b))

alert("Only Numbers are allowed");

else if(c!=d)

{
alert("Enter Same Password");

</script>

<form onsubmit="data1()">

User ID: <input type="text" id="n1"> <br><br>

Contact Number: <input type="text" id="n2"><br><br>

Password: <input type="password" id="n3"><br><br>

Confirm Password: <input type="password" id="n4"><br><br>

Email:<input type="email" id="n5">

<input type="submit" value="Submit Data">

</form>

</body>

</html>

Output:

You might also like