KEMBAR78
Form Validation | PDF | Computer Security | Security
0% found this document useful (0 votes)
13 views4 pages

Form Validation

The document is an HTML form that includes fields for username, password, confirm password, mobile number, and email, along with validation checks implemented in JavaScript. The validation ensures that the fields are filled correctly, checking for length, character types, and format for each input. Error messages are displayed next to each field if the validation fails.

Uploaded by

Dani Gedefa
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)
13 views4 pages

Form Validation

The document is an HTML form that includes fields for username, password, confirm password, mobile number, and email, along with validation checks implemented in JavaScript. The validation ensures that the fields are filled correctly, checking for length, character types, and format for each input. Error messages are displayed next to each field if the validation fails.

Uploaded by

Dani Gedefa
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

<!

DOCTYPE html>

<html>

<head>

<title>javascript</title>

<style type="text/css">

.error{

color: red;

</style>

</head>

<body>

<form onsubmit="return form_validation()">

username <input type="text" name="fname" id="user" autocomplete="off">

<span class="error" id="userid"></span><br><br>

password <input type="text" name="password" id="psw">

<span class="error" id="pswid"></span><br><br>

confirm password <input type="text" name="confirm" id="conpass">

<span class="error" id="conid"></span><br><br>

mobile <input type="text" name="mobile" id="mobile">

<span class="error" id="mobid"></span><br><br>

email <input type="text" name="email" id="email">

<span class="error" id="emailid"></span><br><br>

<input type="submit" name="submit">

<script type="text/javascript">

function form_validation(){

1
var user=document.getElementById('user').value;

var pass=document.getElementById('psw').value;

var conpass=document.getElementById('conpass').value;

var mobile=document.getElementById('mobile').value;

var email=document.getElementById('email').value;

if (user=="") {

document.getElementById("userid").innerHTML=" pleaase fill usrname field";

return false;

if ((user.length <=2) || (user.length >=20)){

document.getElementById("userid").innerHTML=" *length must be between 2 and 20";

return false;

if (!isNaN(user)) {

document.getElementById("userid").innerHTML=" *only characters are allowed";

return false;

if (pass=="") {

document.getElementById("pswid").innerHTML=" pleaase fill password field";

return false;

2
if(pass.length <=5){

document.getElementById("pswid").innerHTML= "password must be atleast 6 length";

return false;

if (conpass != pass) {

document.getElementById("conid").innerHTML= "password not matching";

return false;

if (mobile=="") {

document.getElementById("mobid").innerHTML= "mobile number field cannot be empty";

return false;

if (isNaN(mobile)) {

document.getElementById("mobid").innerHTML= "only numbers are allowed";

return false;

if (mobile.length !=10) {

document.getElementById("mobid").innerHTML= "mobile number must be 10 digits";

return false;

if (email=="") {

document.getElementById("emailid").innerHTML= "please fill email address field";

return false;

3
if(email.indexOf('@')<=0){

document.getElementById("emailid").innerHTML= "invalid email address @";

return false;

if ((email.charAt(email.length-4)!='.') (email.charAt(email.length-3)!='.')){

document.getElementById("emailid").innerHTML= "invalid email address .";

return false;

</script>

</form>

</body>

</html>

You might also like