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

Problem 6:form Validation Using JS: Program Code

The document describes creating a HTML registration form and validating the form entries using JavaScript. It checks that the password is at least 6 characters, the mobile number is 10 digits, and displays alert messages for any validation errors. When the form is correctly filled, it alerts "successfully entered the data". The code sample provides the HTML form and JavaScript validation function to perform these checks.

Uploaded by

Sreelakshmi Sjp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
332 views

Problem 6:form Validation Using JS: Program Code

The document describes creating a HTML registration form and validating the form entries using JavaScript. It checks that the password is at least 6 characters, the mobile number is 10 digits, and displays alert messages for any validation errors. When the form is correctly filled, it alerts "successfully entered the data". The code sample provides the HTML form and JavaScript validation function to perform these checks.

Uploaded by

Sreelakshmi Sjp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

6: Form Validation using JS Date: 14/08/2019

Problem 6:Form Validation Using JS

AIM:

Create a HTML form and perform form validation using JS. Report errors using alert messages.

PROGRAM CODE:

dup.html <html>
<body>
<script>
function validateform()
{
var name=document.myform.name.value;
var password=document.myform.password.value;
var mobileno=document.myform.mobileno.value;
var emailid=document.myform.emailid.value;

if(password.length<6)
{
alert("Password must be at least 6 characters
long");
return false;
}

else if(mobileno.length!=10 || mobileno==null)


{
alert("mobile number is wrong");
return false;
}

else
{
alert("successfully entetred the data");
}
}
</script>
<body style="background-color:lightgreen">

Web Programming Lab 1


6: Form Validation using JS Date: 14/08/2019

<form name="myform" method="post" onsubmit="return


validateform()">
<h1><center>REGISTRATION FORM</center></h1>
USERNAME:<input type="text" name="name" required><br>
<br><br>
PASSWORD:<input type="password"
name="password"required><br> <br><br>
MOBILE NO:<input type="number"
name="mobileno"required><br><br><br>
EMAIL ID:<input type="email"
name="emailid"required><br><br><br>

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


</form>
</body>
</html>

RESULT:

I created a HTML form and performed form validation using java script. It reported errors
through alert messages.After successfully entering the values it show a alert message saying
that “successfully entered the data”.

Fig1: Validation form.

Web Programming Lab 2


6: Form Validation using JS Date: 14/08/2019

Fig2:Alert message after entering the data

Web Programming Lab 3

You might also like