Professional Documents
Culture Documents
Objective:
1. Problem Statement: - To write JavaScript to validate the E-mail and the
Phone number 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 E-mail id and Phone
number 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).
function validatePhone(){
var phone=document.myform.phone.value;
var email=document.myform.email.value;
if(phone==null||phone==""){
alert("Enter Phone Number.");
return false;
}
else if(phone.length!=10){
alert("Phone Number must be of 10 digits.");
return false;
}
else if((/^[0-9]{10}$/).test(phone)==false){
alert("Phone Number must contains only numbers.");
return false;
}
else if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+
$/.test(email)==false){
alert("Invalid Email-id.");
return false;
}
}
OUTPUT: