Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member jf1288's Avatar
    Join Date
    Sep 2003
    Posts
    215
    Member #
    3300
    I ran into this problem as i was coding some script that would validate a form. Heres the script:
    <script language="JavaScript">
    function validate(){
    form = document.mailer;
    sender = form.SenderName.value;
    email = form.SenderEmail.value;
    subject = form.Subject.value;
    message = form.Message.value;
    //if i send it, automatically slap in my email
    if ( name.toLowerCase() == "me" ){
    form.SenderEmail.value = "email@jordanf.com";
    }
    // did they enter a name
    if (name == ""){
    alert("Enter your name.");
    return false
    }
    //did they enter an email
    if (email == ""){
    alert("Enter your email address.");
    return false
    } else {
    if(email != RegExp([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})){
    alert("Please enter a valid email.");
    return false
    }
    }
    //did they enter a message
    if (message == "") {
    alert("Enter a message.");
    return false
    }
    } //end of validate

    function checkform() {
    if ( validate() ) {
    document.form.submit();
    }
    }
    </script>
    One thing im a little hesitant about is my RegExp. I copied it out of some php i found, but i don't think that it has the right syntax. Could i get someone who has experiance with RegExp's to check that one out? It's supposed to check if they entered an email in the correct format.

    The other thing i want to fix is that the button in my email form is supposed to run the check() function, although i always get some strange error.

    Here's the code for said button:
    <INPUT type="button" name="sender" value="Send it!" onClick="checkform();">
    Take a look at the actual page if failed to include some code you guys need.

    ------------------
    Thanks for any help,
    Jordan
    If its not in Family Guy its not worth it.

  2.  

  3. #2
    Senior Member mixu's Avatar
    Join Date
    Aug 2003
    Posts
    217
    Member #
    2815
    This doesn't give any errors, but I can't see the idea of this RegExp..
    Code:
    RegExp(/[\_\.0-9a-z]+@([0-9a-z][0-9a-z]+\.)+[a-z]{2,3}/)
    Ummm...
    1) match (_, ., 0-9, a-z) once or more
    2) match @
    3) match following once or more:
    3a) match 0-9,a-z once
    3b) match 0-9,a-z once or more
    4) match [a-z] twice or thrice

    This doesn't look like an email..

    try this:
    function isEmail(s){
    alphachars = "abcdefghijklmnopqrstuvwxyz";
    numchars = "0123456789";
    specchars = "_.";
    if (s.indexOf("@") != -1) {
    // string must contain @
    x = 0;
    while (s.charAt(x) != "@") {
    if ((alphachars.indexOf(s.charAt(x)) < 0) && (numchars.indexOf(s.charAt(x)) < 0) && (specchars.indexOf(s.charAt(x)) < 0)) {return false;}
    x++;
    }
    x++;
    temp = s.substring(x+1, s.length);
    if ((temp.indexOf(".") == -1) || (temp.charAt(temp.length-1) == ".")) {return false;
    // there must be a . after the @ but not immeadiately after it.
    }
    while (x < s.length){
    if ((alphachars.indexOf(s.charAt(x)) < 0) && (numchars.indexOf(s.charAt(x)) < 0) && (s.charAt(x) != ".")) {return false;}
    x++;
    }
    } else {return false;}
    return true;
    }
    It might have some bugs, I just wrote it off my head.

    Use it like this:
    Code:
    if(isEmail(email)){
    alert("Please enter a valid email.");
    return false;
    }
    EDIT: text made smaller using quote...

  4. #3
    Senior Member mixu's Avatar
    Join Date
    Aug 2003
    Posts
    217
    Member #
    2815
    whoops, use
    Code:
    if(!(isEmail(email))){
    since you want to catch invalid email addresses...

  5. #4
    Senior Member jf1288's Avatar
    Join Date
    Sep 2003
    Posts
    215
    Member #
    3300
    thanks man, awsome help.
    If its not in Family Guy its not worth it.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:14 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com