JS 6

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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