Adblock breaks this site

Validate E-Mail

Discussion in 'Web Programming' started by JavaScriptBank, Dec 7, 2009.

  1. JavaScriptBank

    JavaScriptBank Newcomer
    Banned

    Joined:
    Sep 25, 2009
    Posts:
    17
    Referrals:
    0
    Sythe Gold:
    0
    Validate E-Mail

    This JavaScript verifies that a string looks like a real e-mail address.... detail at JavaScriptBank.com - 2.000+ free JavaScript codes


    How to setup

    Step 1: Use JavaScript code below to setup the script
    JavaScript
    Code:
    <script language="javascript">
    // Created by: Francis Cocharrua :: http://scripts.franciscocharrua.com/
    
    function Validate_String(string, return_invalid_chars) {
      valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
      invalid_chars = '';
      if(string == null || string == '')
         return(true);
    
      //For every character on the string.   
      for(index = 0; index < string.length; index++) {
        char = string.substr(index, 1);                        
         
        //Is it a valid character?
        if(valid_chars.indexOf(char) == -1) {
          //If not, is it already on the list of invalid characters?
          if(invalid_chars.indexOf(char) == -1) {
            //If it's not, add it.
            if(invalid_chars == '')
              invalid_chars += char;
            else
              invalid_chars += ', ' + char;
          }
        }
      }
                
      //If the string does not contain invalid characters, the function will return true.
      //If it does, it will either return false or a list of the invalid characters used
      //in the string, depending on the value of the second parameter.
      if(return_invalid_chars == true && invalid_chars != '') {
        last_comma = invalid_chars.lastIndexOf(',');
        if(last_comma != -1)
          invalid_chars = invalid_chars.substr(0, $last_comma) + 
          ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
        return(invalid_chars);
        }
      else
        return(invalid_chars == ''); 
    }
    
    
    function Validate_Email_Address(email_address){
      // Modified and tested by Thai Cao Phong, JavaScriptBank.com
      //Assumes that valid email addresses consist of [email protected]
      
      at = email_address.indexOf('@');
      dot = email_address.indexOf('.');
    
      if(at == -1 || 
        dot == -1 || 
        dot <= at + 1 ||
        dot == 0 || 
        dot == email_address.length - 1)
      {
      	alert("Invalid email");
        return(false);
      }
         
      user_name = email_address.substr(0, at);
      domain_name = email_address.substr(at + 1, email_address.length);                  
    
      if(Validate_String(user_name) === false || Validate_String(domain_name) === false)
      {
      	alert("Invalid email");
        return(false);
      }
    
      alert("Valid email");//return(true);
    }
    </script>
    	<!--
        	This script downloaded from www.JavaScriptBank.com
        	Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
    	-->
    
    Step 2: Place HTML below in your BODY section
    HTML
    Code:
    <form name=f>
    <input type=text name=mail value="">
    <input type=button value=Check onclick="Validate_Email_Address(document.f.mail.value)">
    </form>
    	<!--
        	This script downloaded from www.JavaScriptBank.com
        	Come to view and download over 2000+ free javascript at www.JavaScriptBank.com
    	-->
    





     
  2. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    Validate E-Mail

    Dude, where did you learn this crap?

    Code:
    <SCRIPT LANGUAGE="JavaScript"><!--
     var re = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$");
     var email = document.form.email.value;
      if (email.match(re)) {
        alert("Successful match");
      } else {
        alert("No match");
      }
    // -->
    </SCRIPT>
    
    

    I also recommend you check out the real valid chars. ~ or ^ are not allowed by email address standards.
    Most email providers list invalid characters as "! # $ % * / ? | ^ { } ` ~"
     
  3. SuF

    SuF Legend
    Pirate Retired Global Moderator

    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary
    Validate E-Mail

    ^He is just reposting shit from a website.
     
  4. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    Validate E-Mail

    I know. But the script is crap.
    Just providing a better alternative, while expressing some anger at, what is probably, a bot.
     
  5. TDD

    TDD Web Design Expert
    Do Not Trade

    Joined:
    Nov 20, 2005
    Posts:
    3,191
    Referrals:
    2
    Sythe Gold:
    0
    Validate E-Mail

    LOL! Very funny backlinking there, funniest still is why would you use JavaScript for validation that should be done back-end, as JavaScript could simply be disabled and voila! Infinite random emails used.
     
  6. blindkilla

    blindkilla Guru
    $25 USD Donor New

    Joined:
    Jun 22, 2005
    Posts:
    1,896
    Referrals:
    0
    Sythe Gold:
    6
    Discord Unique ID:
    282000633404456960
    Discord Username:
    sogord
    Validate E-Mail

    lol, I would also going to ask why he just doesn't use a regular expression and save himself a page worth of writing.
     
< Refresh Page - Automatic | Where can I learn phpbb programming? >


 
 
Adblock breaks this site