Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Name
  2.  
  3. // a function that will determine if an email address contains both "." and "@" symbols
  4.  
  5. // a function that will return the username portion of an email address
  6.  
  7. // a function that will return the domain portion of an email address
  8.  
  9. function btnParseAddress_onclick()
  10. {
  11.     // assign textbox elements to variables for easier access
  12.     var addressTextbox = document.getElementById("txtAddress");
  13.     var outputTextbox = document.getElementById("txtOutput");
  14.    
  15.     var emailAddress = addressTextbox.value;
  16.    
  17.     if(validEmail(emailAddress)){
  18.         //Very important and meaningful message, as the project requires!
  19.         outputTextbox.value =
  20.             "User: " + emailUsername(emailAddress) + "\nDomain:" + emailDomain(emailAddress) +
  21.             "\n\nWelcome to nakedgirls.com!\n" +
  22.             "\n\nAs the only member to have registered over 13+ million movie rentals," +
  23.             "we thought it would be only fair to send you an honorary \"Golden Phalus\"!\n\nThank you very much.";
  24.     }
  25.     else{
  26.         outputTextbox.value = "Invalid Email Address";
  27.     }
  28. }
  29.  
  30. function validEmail(emailAddress){
  31.     for(i = 0; i < emailAddress.length; i++){
  32.         if(emailAddress.charAt(i) == '@'){
  33.             for(j = 0; j < emailAddress.length; j++){
  34.                 if(emailAddress.charAt(j) == '.'){
  35.                     return true;
  36.                 }
  37.             }
  38.             //In case some idiot fills the field with a million '@'s; doesn't get called multiplicative.
  39.             return false;
  40.         }
  41.     }
  42.     return false;
  43. }
  44.  
  45. function emailUsername(emailAddress){
  46.     var splitValue = emailAddress.split('@');
  47.     return splitValue[0];
  48. }
  49.  
  50. function emailDomain(emailAddress){
  51.     var splitValue = emailAddress.split('.');
  52.     return splitValue[splitValue.length - 1];
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement