Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Name
- // a function that will determine if an email address contains both "." and "@" symbols
- // a function that will return the username portion of an email address
- // a function that will return the domain portion of an email address
- function btnParseAddress_onclick()
- {
- // assign textbox elements to variables for easier access
- var addressTextbox = document.getElementById("txtAddress");
- var outputTextbox = document.getElementById("txtOutput");
- var emailAddress = addressTextbox.value;
- if(validEmail(emailAddress)){
- //Very important and meaningful message, as the project requires!
- outputTextbox.value =
- "User: " + emailUsername(emailAddress) + "\nDomain:" + emailDomain(emailAddress) +
- "\n\nWelcome to nakedgirls.com!\n" +
- "\n\nAs the only member to have registered over 13+ million movie rentals," +
- "we thought it would be only fair to send you an honorary \"Golden Phalus\"!\n\nThank you very much.";
- }
- else{
- outputTextbox.value = "Invalid Email Address";
- }
- }
- function validEmail(emailAddress){
- for(i = 0; i < emailAddress.length; i++){
- if(emailAddress.charAt(i) == '@'){
- for(j = 0; j < emailAddress.length; j++){
- if(emailAddress.charAt(j) == '.'){
- return true;
- }
- }
- //In case some idiot fills the field with a million '@'s; doesn't get called multiplicative.
- return false;
- }
- }
- return false;
- }
- function emailUsername(emailAddress){
- var splitValue = emailAddress.split('@');
- return splitValue[0];
- }
- function emailDomain(emailAddress){
- var splitValue = emailAddress.split('.');
- return splitValue[splitValue.length - 1];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement