0% found this document useful (0 votes)
34 views4 pages

JS 6

The document describes an experiment to write JavaScript code to validate name and password fields on a registration page. The code should check that the name contains only alphabets and is at least 6 characters, and that the password is at least 6 characters. The solution involves accessing the form elements with DOM manipulation, writing validation logic in JavaScript, saving as a .js file, and linking it to the HTML page. The provided code defines a validateform() function that checks the name and password values against these criteria and alerts the user of any invalid inputs.
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)
34 views4 pages

JS 6

The document describes an experiment to write JavaScript code to validate name and password fields on a registration page. The code should check that the name contains only alphabets and is at least 6 characters, and that the password is at least 6 characters. The solution involves accessing the form elements with DOM manipulation, writing validation logic in JavaScript, saving as a .js file, and linking it to the HTML page. The provided code defines a validateform() function that checks the name and password values against these criteria and alerts the user of any invalid inputs.
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/ 4

Experiment : 6

Aim: Write JavaScript to validate the following fields of the


above registration page.
 Name (Name should contains alphabets and the length should not be less
than 6 characters).
 Password (Password should not be less than 6 characters length).

Objective:
1. Problem Statement: - To write JavaScript to validate the Name and the
Password field of the Registration Page.

2. Stepwise Solution: -
 Initiate the JS Page by accessing the elements from HTML file using
DOM manipulation.
 Use the logics of JavaScript to validate the Name and Password fields
of the Registration page.
 Save the file using .js extension.
 Link the JavaScript file with the HTML file using script tag.
 Run the HTML file on browser (IE / google-chrome / Mozilla-firefox).

Code & Outcome: - Snapshots of the Registration Page.


CODE:
function validateform() {
var Name = document.myform.name.value;
var password = document.myform.password.value;

if (Name == null || Name == "") {


alert("Name can't be blank.");
return false;
}
else if (Name.length < 6) {
alert("Name must be atleast 6 characters.");
return false;
}
else if ((/^[a-zA-Z]/.test(Name)) == false) {
alert("Name must contains only Alphabets.");
return false;
}
else if (password == null || password == "") {
alert("Enter Password.");
return false;
}
else if (password.length < 6) {
alert("Password must be atleast 6 characters
long.");
return false;
}
else{
alert("Form Submitted.");
}
}
OUTPUT:

You might also like