Closed Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Thread: help with email validation

  1. #1
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    help with email validation

    Hi All,

    I've added a line to make sure the email address is not blank...but I can't get the validation part working. if i uncomment the commented lines in red, i get the error: error '8004020e' ...this has to do with validation when i google. am i using that validator the wrong way?

    Code:
    <script>
    function onSubmitForm() {
        var formDOMObj = document.frmSend;
    
        if (formDOMObj.EqNo.value == "")
    	alert("Please enter EQNumber!")
        if (formDOMObj.EqDesc.value == "")
    	alert("Please enter EQDescription!")
        if (formDOMObj.EmailAdd.value == "")
    	alert("Please enter your email address!")
       // if (emailValidator(formDOMObj.EmailAddress.value,"Please enter a valid email address"))    else
            return true;
        return false;
    }
    
    //function emailValidator(){
    //	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    //	if(formDOMObj.EmailAdd.match(emailExp)){
    //		return true;
    //	}
    //else{
    //		return false;
    //	}
    //}
    </script>
    
    Thanks peeps!!!!

  2. #2
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    436
    Rep Power
    7

    okay, my javascript is not the greatest. but try something like this
    Code:
    <script>
    function onSubmitForm() {
        var formDOMObj = document.frmSend;
        var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    
        if (formDOMObj.EqNo.value == "")
    	alert("Please enter EQNumber!")
        if (formDOMObj.EqDesc.value == "")
    	alert("Please enter EQDescription!")
        if (formDOMObj.EmailAdd.value == "")
    	alert("Please enter your email address!")
        if (!(formDOMObj.EmailAdd.match(emailExp)))
        	alert("Please enter a valid email address")
        return false;
    }
    </script>
    
    Quote of the Month:
    Leaders: Leaders are like eagles. We don't have either of them here.

    Questions to Ponder:
    Why do banks charge you a "non-sufficient funds fee" on money they already know you don't have?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    1,724
    Blog Entries
    10
    Rep Power
    11

    You'll need to return true at some point or the form won't submit. Using mehere's example, try this:-
    Code:
    function onSubmitForm() {
        var formDOMObj = document.frmSend;
        var emailExp = new RegExp("^[\w\-\.\+]+@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$");
     
        if (formDOMObj.EqNo.value == ""){
        alert("Please enter EQNumber!");
        return false;
        }
        if (formDOMObj.EqDesc.value == ""){
        alert("Please enter EQDescription!");
        return false;
        }
        if (!emailExp.test(formDOMObj.EmailAdd.value)){
        alert("Please enter a valid email address");
        return false;
        }
        return true;
    }
    </script>
    
    You shouldn't need to check for a blank email because it won't pass the regex test.

    Hope that helps.

    <edit>I couldn't get it to work using \w. You could try this expression "^[A-Za-z0-9\-.+]+@[A-Za-z0-9.-]+[.]+[A-Za-z]{2,4}$" That will only accept email addresses in the format name@domain.ext You may want to accept emails with name@domain in which case change +[.] to +\. </edit>
    Last edited by richyrich; August 20th, 2008 at 02:49 PM.

  4. #4
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Thanks Mehere & RR....

    RR, I tried the below but it didn't work, kept getting error 8004020e...and it no longer alerted for the other fields. So, the only way to not get the error was to comment out the lines.

    Code:
    <script>
    function onSubmitForm() {
        var formDOMObj = document.frmSend;
    //    var emailExp = new RegExp("^[\w\-\.\+]+@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$");
     
        if (formDOMObj.EqNo.value == ""){
        alert("Please enter EQNumber!");
        return false;
        }
        if (formDOMObj.EqDesc.value == ""){
        alert("Please enter EQDescription!");
        return false;
        }
    //    if (!emailExp.test(formDOMObj.EmailAdd.value)){
    //    alert("Please enter a valid email address");
    //    return false;
    //    }
        return true;
    }
    </script>
    
    So I tried the var line from mehere, and it worked with your if , alert, return... like below:

    Code:
    <script>
    function onSubmitForm() {
        var formDOMObj = document.frmSend;
        var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/; 
        if (formDOMObj.EqNo.value == ""){
        alert("Please enter EQNumber!");
        return false;
        }
        if (formDOMObj.EqDesc.value == ""){
        alert("Please enter EQDescription!");
        return false;
        }
        if (!emailExp.test(formDOMObj.EmailAdd.value)){
        alert("Please enter a valid email address");
        return false;
        }    return true;
    }
    </script>
    
    On this, do you mean they wouldn't have to enter the .com, .net, etc? i think i need the whole thing...(.com) because I am using asp mail (cdo).
    <edit>I couldn't get it to work using \w. You could try this expression "^[A-Za-z0-9\-.+]+@[A-Za-z0-9.-]+[.]+[A-Za-z]{2,4}$" That will only accept email addresses in the format name@domain.ext You may want to accept emails with name@domain in which case change +[.] to +\. </edit>

  5. #5
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    1,724
    Blog Entries
    10
    Rep Power
    11

    Do you mean a JS error or an ASP error?

  6. #6
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    hmmm...not sure...maybe asp?

    error '8004020e'

    the line is 222 which is from my cdo code...

    this line:

    Code:
    .Send
    

  7. #7
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    1,724
    Blog Entries
    10
    Rep Power
    11

    That is an error with CDO, normally related to an invalid email address.

    When you uncomment the JS code and enter something like 'Rebelle' in the email text box, what happens?

  8. #8
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Hi RR,

    If i uncomment the line and enter Rebelle...I don't get the error but I also leave the other fields blank so i could get alert but I don't get the alerts.....

    it's when i leave the email address field blank that I get the error......but when i leave the other fields blank too, i don't get any alerts....just the error.

  9. #9
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    1,724
    Blog Entries
    10
    Rep Power
    11

    The speech marks are missing off this line:-
    Code:
    var emailExp = "/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$"; 
    <edit>Actually, this line is all wrong. See how mine was:-
    Code:
    var emailExp = new RegExp("^[\w\-\.\+]+@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$");
    
    We're using regular expressions to test for a match of this pattern. You have to define it as a RegExp pattern</edit>
    Last edited by richyrich; August 21st, 2008 at 09:19 AM.

  10. #10
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    ok...i retried and retried with the original line but same thing kept happening.

    so I tried changing the " and " to / and / ... like below:

    from:

    Code:
    var emailExp = new RegExp("^[\w\-\.\+]+@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$");
    
    to:

    Code:
    var emailExp = new RegExp(/^[\w\-\.\+]+@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/);
    
    will this cause any issues doing it like this?

Closed Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. validation
    By todd2006 in forum JavaScript Programming
    Replies: 5
    Last Post: July 30th, 2008, 09:23 AM
  2. date validation
    By todd2006 in forum JavaScript Programming
    Replies: 3
    Last Post: July 6th, 2008, 11:39 AM
  3. textbox validation
    By todd2006 in forum JavaScript Programming
    Replies: 6
    Last Post: July 2nd, 2008, 01:30 PM
  4. checkbox validation
    By todd2006 in forum JavaScript Programming
    Replies: 3
    Last Post: June 18th, 2008, 07:22 PM
  5. Programmatically Add Item to Validation Summary
    By jmurrayhead in forum .Net Code Samples
    Replies: 0
    Last Post: March 20th, 2008, 09:41 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO