Results 1 to 5 of 5

Thread: Form E-Mail Validation Help..

  1. #1
    Join Date
    Nov 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Form E-Mail Validation Help..

    Hi people,

    Just struggling a little with some scripting..

    I've got this form with 3 fields(Name, Email, Idea) and i've currently got some javascript validating it, to make sure that each field has text entered within it.

    Code:
    <script language="JavaScript" type="text/javascript" >
    function validate_form ( )
    
    {
    
    
    
        valid = true;
    		if ( document.comp.name.value == "" ) 
    		{
    			alert ( "please provide your name!" );
    			valid = false;
    		}
    	else
    		if ( document.comp.email.value == "" )
    		{
    			alert ( "please provide your email address!" );
    			valid = false;
    		}
    	else
    		if ( document.comp.idea.value == "" )
    		{
    			alert ( "please provide an idea for our student accommodation site" );
    			valid = false;
        	}
    		return valid;
    		
    		
    
    		
    		
    }
    </script>

    I call this in my form, and it works fine..

    Code:
    <form name="comp" action="sendmail.php" method="post" onsubmit="return validate_form ( );" >

    However, I wish to add some extra validation to the "email" field. I've seen plenty of email validation scripts around, but i'm not sure how to incorporate it, as it will be two different functions altogether. I guess I sound like a noob, i'm just not very skilled up when it comes to javascript!

    Any help appreciated!

    Cheers,

    Sal

  2. #2
    Join Date
    Nov 2006
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    if ( document.comp.email.value == "" || NEW condition || ... )

  3. #3
    Join Date
    Nov 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Acey99 View Post
    if ( document.comp.email.value == "" || NEW condition || ... )
    Cheers for that matey, if i'm right that's the OR operator in an IF statement? I have tried this, but maybe i've been botching it up somewhere..

    I'd be really grateful if you could show me how to incorporate the IF statement with OR, with the E-Mail validation script provided by Dynamic Drive.

    Code:
    <script type="text/javascript">
    
    /***********************************************
    * Email Validation script- © Dynamic Drive (www.dynamicdrive.com)
    * This notice must stay intact for legal use.
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
    
    function checkmail(e){
    var returnval=emailfilter.test(e.value)
    if (returnval==false){
    alert("Please enter a valid email address.")
    e.select()
    }
    return returnval
    }
    
    </script>
    Many thanks,

    Sal

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Code:
    <script type="text/javascript">
    
    /***********************************************
    * Email Validation script- © Dynamic Drive (www.dynamicdrive.com)
    * This notice must stay intact for legal use.
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    function validate_form ( )
    
    {
    
        valid = true;
    		if ( document.comp.name.value == "" ) 
    		{
    			alert ( "please provide your name!" );
    			valid = false;
    		}
    	else
    		var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
    		var returnval=emailfilter.test(document.comp.email.value);
    		if (returnval==false){
    		alert("Please enter a valid email address.");
    		valid = false;
    		if ( document.comp.email.value == "" || valid == false )
    		{
    			alert ( "please provide your VALID email address!" );
    			valid = false;
    		}
    	else
    		if ( document.comp.idea.value == "" )
    		{
    			alert ( "please provide an idea for our student accommodation site" );
    			valid = false;
        	}
    		return valid;
    			
    }
    
    </script>
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Nov 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Cheers for that mate, unfortunately it didn't work though. I think a "}" was missed to close the 1st IF statement for the email condition. However, I corrected that, but it doesn't work.

    All the fields are blank, and when I press the button, the popup appears "please provide your name" and the form just submits.

    Any additional help really appreciated!

    Regards,

    sal

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
  •