+ Reply to Thread
Results 1 to 3 of 3

Thread: Email Check JavaScript

  1. #1
    willemvo's Avatar
    willemvo is offline x10Hosting Member willemvo is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    19

    Question Email Check JavaScript

    I've builded this poorly looking script,, but i need it so can anybody tell me what i did wrong with the array and the indexOf function... PLEASE HELP ME!!
    Code:
    <html>
    <head>
    <title>TEST</title>
    </head>
    <body>
    <SCRIPT language="JavaScript">
    <!--
    function emailcheck(form)
    {
     var email=form.email.value;
     
     var c = new array();
     c[0] = "hotmail";
     c[1] = "home";
     c[2] = "live";
    
     var acheck=email.indexOf('@');
     var dotcheck=email.indexOf('.');
     var procheckhot=email.indexOf(c);
    
     if ((acheck==-1) || (dotcheck==-1) || (procheckhot==-1))
      { 
       alert("Error: FOUT!!!\n\tno @ or;\n\tno . or;\n\ta combination.");
       emailcheck()
      }
     else
      {
       alert('Thanks!');
      }
    }
    //-->
    </SCRIPT>
    <form>
    <input type="text" name="email" value="your e-mail adress" /><input type="button" value="CHECK!!" name="button" onClick="emailcheck(this.form)" />
    </form>
    </body>
    </html>
    thanks in advance

  2. #2
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: Email Check JavaScript

    It's only a very simple problem.
    In JavaScript, there is no such phrase as 'array()' unless it is a variable.
    If you are creating an array, the a must be capitalised.

    Code:
    var c = new Array();


    Edit:
    Oh, just noticed that you have an error in your logic as well.
    You're also testing whether the email address is from hotmail, or otherwise contains the strings "hotmail", "home" or "live".
    So the email address "me@gmail.com" will be invalid, but "@home." will be a valid email address!!

    Below I include a better function which I have adapted so that you can seamlessly put it into your script without the need to change anything.
    Code:
    function emailcheck(form){
    var email=form.email.value;
    
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(email)){
      alert('Thanks, valid email address!');
      }
    else{
      alert("Error: Not a valid email address.");
      emailcheck()
      }
    }
    Last edited by Scoochi2; 09-04-2008 at 06:36 PM. Reason: Automerged Doublepost
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  3. #3
    willemvo's Avatar
    willemvo is offline x10Hosting Member willemvo is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    19

    Re: Email Check JavaScript

    Thanx man!!! PLEASE CLOSE THIS THREAD

+ Reply to Thread

Similar Threads

  1. Cant send or receive email
    By hectorga in forum Free Hosting
    Replies: 0
    Last Post: 03-17-2008, 11:54 AM
  2. email settings - still having problem
    By Burnjob in forum Free Hosting
    Replies: 11
    Last Post: 10-21-2007, 07:56 AM
  3. Email Settings
    By Burnjob in forum Free Hosting
    Replies: 5
    Last Post: 10-19-2007, 01:16 PM
  4. Cuentas email
    By Kansy in forum Soporte
    Replies: 5
    Last Post: 01-03-2007, 05:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers