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

Assignment 2 Web

This document contains the code for a student registration form with various input fields like name, semester, registration number, CNIC, email, and enrollment number. It includes JavaScript form validation functions to validate the input in each field on form submission. Some key validation checks include verifying the semester is a number, email is in a valid format, CNIC matches the expected pattern, and enrollment number matches the expected format. If any validation check fails, an error alert will be displayed.

Uploaded by

Fayeza
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)
48 views6 pages

Assignment 2 Web

This document contains the code for a student registration form with various input fields like name, semester, registration number, CNIC, email, and enrollment number. It includes JavaScript form validation functions to validate the input in each field on form submission. Some key validation checks include verifying the semester is a number, email is in a valid format, CNIC matches the expected pattern, and enrollment number matches the expected format. If any validation check fails, an error alert will be displayed.

Uploaded by

Fayeza
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

FAIZA SAEED WEB ENGINEERING 02-134181-003

ASSIGNMENT # 2
CODE:

<!DOCTYPE html>

<html> form ul li input, select, span {

<head> float: left;

<style> margin-bottom: 10px;

body { }

h1 {

margin-left: 70px; form textarea {

} float: left;

form li { width: 350px;

list-style: none; height: 150px;

margin-bottom: 5px; }

[type="submit"] {

form ul li label{ clear: left;

float: left; margin: 20px 0 0 230px;

clear: left; font-size:18px

width: 100px; }

text-align: right;

margin-right: 10px; p{

font-family:Verdana, Arial, Helvetica, sans- margin-left: 70px;


serif;
font-weight: bold;
font-size:14px;
}
}
FAIZA SAEED WEB ENGINEERING 02-134181-003

} {

</style> }

</head> }

<body> }

<script>

function formValidation() }

{ }

var uname = document.registration.name;

var sem = document.registration.sem; return false;

var reg = document.registration.reg;

var CNIC = document.registration.cnic; }

var enroll = document.registration.enroll;

var uemail = document.registration.email; function allLetter(uname)

if(ValidateEmail(uemail)) var letters = /^[A-Za-z]+$/;

{ if(uname.value.match(letters))

if(Validatesem(sem)) {

{ return true;

if(Validateenroll(enroll)) }

{ else

if(Validatecnic(cnic)) {

{ alert('Username must have alphabet


characters only');
if(Validatereg(reg))
uname.focus();
FAIZA SAEED WEB ENGINEERING 02-134181-003

return false; function userid_validation(reg)

} {

} var reg_len = uid.value.length;

function userid_validation(name) if (reg_len == 0 )

{ {

var uname_len = uid.value.length; alert("regestration no should not be empty );

if (uname_len == 0 ) reg.focus();

{ return false;

alert("Name should not be empty ); }

uname.focus(); return true;

return false; }

return true; }

} function userid_validation(cnic)

} {

function userid_validation(sem) var cnic_len = uid.value.length;

{ if (cnic_len == 0 )

var sem_len = uid.value.length; {

if (sem_len == 0 ) alert("CNIC should not be empty );

{ cnic.focus();

alert("Semester should not be empty ); return false;

sem.focus(); }

return false; return true;

} }

return true; }

} function userid_validation(uemail)

} {
FAIZA SAEED WEB ENGINEERING 02-134181-003

var uemail_len = uid.value.length; return true;

if (uemail_len == 0 ) }

{ else

alert("EMAIL should not be empty ); {

uemail.focus(); alert("You have entered an invalid email


address!");
return false;
uemail.focus();
}
return false;
return true;
}
}
}
}
function Validatecnic(cnic)
function userid_validation(enroll)
{
{
var cnicformat = /[1-9]{5}-[1-9]{7}-[1-9]{1}/g;
var enroll_len = uid.value.length;
if(cnic.value.match(cnicformat))
if (enroll_len == 0 )
{
{
return true;
alert("enroll no should not be empty );
}
enroll.focus();
else
return false;
{
}
alert("You have entered an CNIC address!");
return true;
cnic.focus();
}
return false;
}
}
function ValidateEmail(uemail)
}
{
function Validatesem(sem)
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-
]?\w+)*(\.\w{2,3})+$/; {

if(uemail.value.match(mailformat)) var semformat = /^\d+$/;

{ if(sem.value.match(semformat))
FAIZA SAEED WEB ENGINEERING 02-134181-003

{ if(reg.value.match(regformat))

return true; {

} return true;

else }

{ else

alert("You have entered an invalid semester {


detail!");
alert("You have entered an regestration no
sem.focus(); detail!");

return false; reg.focus();

} return false;

} }

function Validateenroll(enroll) }

{ else

var enrollformat = /^[2-9]\d{2}-\d{5}-\d{3}$/;; {

if(enroll.value.match(enrollformat)) alert('Form Succesfully Submitted');

{ window.location.reload()

return true; return true;

} }

else }

alert("You have entered an enroll no detail!"); </script>

enroll.focus();

return false; <h1>Registration Form</h1>

} Use tab keys to move from one input field to


the next.
}
<form name='registration' onSubmit="return
function Validatereg(reg) formValidation();">
{ <ul>
var regformat = /[1-9]{1,5}/g; <li><label for="name">Name:</label></li>
FAIZA SAEED WEB ENGINEERING 02-134181-003

<li><input type="text" name="userid"


size="12" /></li>

<li><label for="sem">semester:</label></li>

<li><input type="text" name="sem" size="12"


/></li>

<li><label for="reg_no">Reg no:</label></li>

<li><input type="text" name="reg_no"


size="50" /></li>

<li><label for="CNIC">CNIC:</label></li>

<li><input type="text" name="CNIC" size="50"


/></li>

<li><label for="email">Email:</label></li>

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


size="50" /></li>

<li><label for="enroll">Enrollment
No:</label></li>

<li><input type="text" name="enroll"


size="50" /></li>

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


value="Submit" /></li>

<h1></h1>

<p></p>

</body>

</html>

You might also like