CS101 VU Current Assignment No. 2 Spring 2012 Solution

Assignment No. 02
Semester: Spring 2012
Introduction to Computing-CS101
Total Marks: 20

Due Date: 02-05-2012

Question 1 [20 marks]

Make a form in HTML document containing only one field named as Email and one Submit Button. Write your own JavaScript function to validate the email address.

The Validation should be as follows:

1. It must accept only your VU Student email address i.e; it must not accept any other student’s VU email address.
2. It must show alert on acceptance or denial of the email address after validation.
3. The name of the function should contain your student ID like CheckEmail_BC102034568.
4. If you enter your wrong student email id then it must show alert as well.
5. It must accept your student ID only at vu.edu.pk, means if you enter BC102034568@hotmail.com then it must not accept it.
6. There must be unique alerts for each error; like if the length of the student ID is larger or smaller than the original ID then the alert should be according to that.
7. During each alert, the entered email address must also be shown in the alert box like: “BC102034560000008@vu.edu.pk is not your Valid Email address”

Hint: See the attached sample html file for simply checking @ and dot in an email address.

Note:

o Assignment should be done by your own efforts, not copied from net, handouts or books.

o You should submit your html file as well as word file containing the code, zip the both files in one single file and upload via your assignment interface.

Solution:

cs101 assignment no 2 solution

 

want to copy the above code? visit: CS101 VU Current Assignment No. 2 Spring 2012 Solution

……………………

<html>
<head>
<script type=”text/javascript”>
function CheckMyEmail()
{
var x=document.forms["myForm"]["email"].value;
var at=x.indexOf(“120200697@”);
var dot=x.lastIndexOf(“.”);
if (at<1 || dot<at+2 || dot+2>=x.length)
{
alert(“OOps…Error…XXX… You entered an invalid email address. check your spelling and try angain…”);
return false;
}
else
{
alert(“Conratulation..! Welcome to VUsolutions.com Now you have Logged in……>>>>>>
you have entered mc120200697@vu.edu.pk your valid email address..”);
}
}
</script>
</head>

<body>
<form name=”myForm” action=”example.html” onsubmit=”return CheckMyEmail();” method=”post”>
Email: <input type=”text” name=”email”>
<input type=”submit” value=”Submit”>
</form>
</body>

</html>

…………………………….

<Html>
<Head>

<script type=”text/javascript”>
function CheckMyEmail_bc000000000()
{
var x=document.forms["myForm"]["email"].value;
var at=x.indexOf(“@”);
var dot=x.lastIndexOf(“.”);
var domain = x.indexOf(“@vu.edu.pk”);
var username = x.lastIndexOf(“bc000000000″);
//alert(domain);
//alert(dot);
//return false;
var arr = x.split(“@”);

if(x == “”){
alert(“Field cannot be empty.”);
return false;
}
else if (at<1 || dot<at+2 || dot+2>=x.length)
{
alert(x+” is not your valid VU e-mail address”);
return false;
}
else if(domain<1){
alert(x+” Email address you entered is not have valid domain.”);
return false;
}
else if(username==-1){
alert(x+” Email address you entered is not have valid student ID.”);
return false;
}
else if(arr[0].length > 11){
alert(arr[0]+” you exceed the limit of your ID.”);
return false;
}
else if(arr[0].length < 10){
alert(arr[0]+” You entered smaller ID.”);
return false;
}
else
{
alert(“Your email (“+x+”) successfully Accepted Email.”);
return false;
}
return false;
}
</script>
</Head>

<Body>
<form name=”myForm” action=”example.html” onSubmit=”return CheckMyEmail_bc000000000();” method=”post”>
Email: <input type=”text” name=”email”>
<input type=”submit” value=”Submit”>
</form>
</Body>

</Html>

Related Posts Plugin for WordPress, Blogger...