CvLTAELG1AAv7GMjp8RSaPGsvS8 CS101 Assignments # 2 Solution Spring 2012 |
Saturday , 20 December 2014
Virtual University New old assignments, papers, GDB, Quizzez
Newest Assignments
You are here: Home - CS101 - CS101 Assignments # 2 Solution Spring 2012

CS101 Assignments # 2 Solution Spring 2012

Question 1         [10 marks]

Make a form in HTML document containing only one filed 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.
  2. It must not accept any other student VU email address.
  3. It must show alert on acceptance or denial of the email address after validation.
  4. The name of the function should contain your student ID like CheckEmail_BC102034568.
  5. If you enter your wrong student email id it must show alert as well.
  6. It must accept your student ID only at gmail.vu.edu.pk means if you enter BC102034568@hotmail.com then it must not accept it.
  7. 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.

  8. During each alert the entered email address must also be shown in the alert box like BC102034568@gmailcom is not your Valid Email address.

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

Note:

  • Assignment should be done by your own efforts not copied from net, handouts or books.
  • You should submit your html file as well word file containing the code, zip the both files in one single file and upload via your assignment interface

Solution:

<script type=”text/javascript”>
function CheckEmail_BC102034568()
{
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(“BC102034568″);
var arr = x.split(“@”);

if(x == “”){
alert(“Field can not 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: —>Error 1″ );
return false;
}
else if(domain<1){
alert(x+” Email address you entered doesn`t contain valid domain.  —> Error 2″);
return false;


}
else if(username==-1){
alert(x+” Email address you entered doesn`t contain valid student ID.  —> Error 3″);
return false;
}
else if(arr[0].length > 11){
alert(arr[0]+” you exceed the limit of your ID.  —> Error 4″);
return false;
}
else if(arr[0].length < 10){
alert(arr[0]+” You entered smaller ID.  —> Error 5″);
return false;
}

else
{
alert(“Your email (“+x+”) successfully Accepted Email. OK”);
return false;
}
return false;
}
</script>

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current ye@r *