TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Master Vids
NA
3
2.4k
how to validate for password and confirm password
Mar 31 2013 7:52 AM
<html>
<head>
<script type="text/javascript">
function validate(){
var firstNaError = checkfirstname();
var lastNaError = checklastname();
var emailError = checkEmail();
var password = checkpassword();
}
function checkfirstname(){
var fname= document.submitform.fname.value;
if ( fname == ""){
document.getElementById("firstname_error").innerHTML = "Please enter firstname";
return false;}
else {
document.getElementById("firstname_error").innerHTML = "";
return true;}
}
function checklastname(){
var lname= document.submitform.lname.value;
if ( lname == ""){
document.getElementById("lastname_error").innerHTML = "Please enter lastname";
return false;}
else {
document.getElementById("lastname_error").innerHTML = "";
return true;}
}
function checkEmail(){
var email = document.submitform.email.value;
if (email == ""){
document.getElementById("email_error").innerHTML = "Please enter Email Address";
return false;}
else {
document.getElementById("email_error").innerHTML = "";
return true;}
}
function checkpassword(){
var pass_len = document.submitform.pass.value.length;
if (pass_len == 0 || pass_len >= 12 || pass_len <6) {
document.getElementById("pass_error").innerHTML = "Please enter password";
return false;}
else {
document.getElementById("pass_error").innerHTML = "";
return true;}
}
}
</script>
</head>
<body>
<h2>Registration</h2>
<table border=0 >
<form name="submitform" method=" action="">
<td>First Name</td>
<td><input type=text name="fname" />
<span style=color:red id="firstname_error"></span><td>
</tr>
<td>Last Name</td>
<td><input type=text name="lname" />
<span style=color:red id="lastname_error"></span><td>
</tr>
<tr>
<td>email* </td>
<td><input type=text name="email" />
<span style=color:red id="email_error"></span>
</td>
</tr>
<tr>
<td>Password*</td>
<td><input type=password name="pass" />
<span style=color:red id="pass_error"></span>
</td>
</tr>
<tr>
<td>Confirm Password*</td>
<td><input type=password name="cpass" />
<span style=color:red id="confirmpass_error"></span>
</td>
</tr>
<td align=center colspan=2><input type="button" value="Create my account" onclick="validate()"/></td>
</tr>
</table>
</form>
</body>
</html>
Reply
Answers (
2
)
IN Operator in javascript?
Regarding Manual Testing in Web application