0% found this document useful (0 votes)
5 views6 pages

Program

The document is an HTML registration form that includes client-side validation using JavaScript. It checks for valid username, password, email, phone number, gender selection, language options, and address before submission. Alerts are displayed for any validation errors, and a success message is shown upon successful registration.

Uploaded by

mdateeq807
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)
5 views6 pages

Program

The document is an HTML registration form that includes client-side validation using JavaScript. It checks for valid username, password, email, phone number, gender selection, language options, and address before submission. Alerts are displayed for any validation errors, and a success message is shown upon successful registration.

Uploaded by

mdateeq807
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/ 6

Client-side validation program for registration form

<html>

<head>

<title> Welcome to NNRG e-Book's website</title>

<script language="javascript">

function validate() {

// username validation

var uname = f1.username.value;

if (uname.length<=0)

alert("Please Enter UserName");

f1.username.focus();

return false;

if (uname.length < 8)

alert("Please enter UserName not less than 8");

f1.username.focus();

return false;

//password validation

var pwd = f1.password.value;

if (pwd.length<=0)

alert("Please Enter password");

f1.password.focus();

return false;

}
if (pwd.length < 6)

alert("Please enter Password not less than 6");

f1.password.focus();

return false;

// email validation

var email = f1.email.value;

if (email.length<=0)

alert("Please Enter email");

f1.email.focus();

return false;

else {

let eflag=false;

for(i=0;i<email.length;i++) {

if(email.charAt(i)=="@")

eflag=true;

if(!(eflag))

alert("Please enter a valid Email ID");

f1.email.focus();

return false;

}
}

// phone number validation

var phno = f1.phno.value;

if (phno.length<=0)

alert("Please Enter Phone Number");

f1.phno.focus();

return false;

if (isNaN(phno))

alert("Please Enter Valid Phone Number");

f1.phno.focus();

return false;

if (phno.length != 10)

alert("Please Enter Valid Phone Number");

f1.phno.focus();

return false;

// gender validation

let flag=false;

for(i=0;i<f1.gen.length;i++)

if(f1.gen[i].checked)

flag=true;

if(!(flag))

{
alert("Please choose a Gender");

return false;

// Language validation

flag=false;

for(i=0;i<f1.lang.length;i++)

if(f1.lang[i].checked)

flag=true;

if(!(flag))

alert("Please select at least one of the Language options.");

return false;

// address validation

var addr = f1.address.value;

if (addr.length<=0)

alert("Please Enter address");

f1.address.focus();

return false;

// to display Success message

alert("Registration Successful");

</script>

</head>

<body>

<center><br>
<h3>Registration Form </h3>

<br/>

<form name="f1">

<table cellpadding="1" align="center" >

<tr><td> User Name:*</td>

<td><input type="text" name="username"></td></tr>

<tr><td>Password:*</td>

<td><input type="password" name="password"></td></tr>

<tr><td>Email ID:*</td>

<td><input type="text" name="email"></td></tr>

<tr><td>Phone Number:*</td>

<td><input type="text" name="phno"></td></tr>

<tr><td valign="top">Gender:*</td>

<td><input type="radio" name="gen" value="Male">Male &nbsp;&nbsp;

<input type="radio" name="gen" value="Female">Female</td></tr>

<tr> <td valign="top">Language Known:*</td>

<td> <input type="checkbox" name="lang" value="English">English<br/>

<input type="checkbox" name="lang" value="Telugu">Telugu<br>

<input type="checkbox" name="lang" value="Hindi">Hindi<br>

<input type="checkbox" name="lang" value="Tamil">Tamil

</td></tr>

<tr> <td valign="top">Address:*</td>

<td><textarea name="address"></textarea></td>

<tr><td></td><td><input type="button" value="SUBMIT" hspace="10"


onclick="validate()">

<input type="reset" value="RESET"></td></tr>

<tr> <td colspan=2 >*<font color="#FF0000">fields are mandatory</font>

</td>
</tr>

</table>

</form>

</center>

</body>

</html>

You might also like