0% found this document useful (0 votes)
43 views2 pages

Instructions:: Objective: To Develop Your Own Javascript Functions and Using Them in Form

The document provides instructions for Assignment 02 in the Introduction to Computing course, which requires students to create a HTML form with an email validation function that checks if the entered email address matches their VU student ID and domain. The validation function must return different error alerts depending on issues like an invalid domain, missing student ID, or ID that is too long or short. Students must submit both the HTML file and a word file containing the JavaScript code for grading.

Uploaded by

Shahbaz Abbasi
Copyright
© Attribution Non-Commercial (BY-NC)
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)
43 views2 pages

Instructions:: Objective: To Develop Your Own Javascript Functions and Using Them in Form

The document provides instructions for Assignment 02 in the Introduction to Computing course, which requires students to create a HTML form with an email validation function that checks if the entered email address matches their VU student ID and domain. The validation function must return different error alerts depending on issues like an invalid domain, missing student ID, or ID that is too long or short. Students must submit both the HTML file and a word file containing the JavaScript code for grading.

Uploaded by

Shahbaz Abbasi
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 2

Assignment No.

02 Solution Semester: Spring 2012 Introduction to Computing-CS101 Total Marks: 20 Due Date: 02-05-2012

Objective: To develop your own JavaScript functions and using them in form.

Instructions:
Please read the following instructions carefully before solving & submitting assignment: Assignment should be in your own wordings not copied from internet, handouts or books. It should be clear that your assignment will not get any credit (zero marks) if:

o o o o

The assignment is submitted after due date. The submitted assignment does not open or file is corrupt. The assignment is copied (from other student or copied from handouts or internet). Student ID is not mentioned in the assignment file or name of file is other than student ID. For any query about the assignment, contact at [email protected]

GOOD LUCK

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. 2. 3. 4. 5. 6. It must accept only your VU Student email address. It must not accept any other student VU email address. It must show alert on acceptance or denial of the email address after validation. The name of the function should contain your student ID like CheckEmail_BC102034568. If you enter your wrong student email id it must show alert as well. It must accept your student ID only at gmail.vu.edu.pk means if you enter [email protected] 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:
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 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>

You might also like