Results 1 to 2 of 2

Thread: Recognize Incorrect E-mail in a form?

  1. #1
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Recognize Incorrect E-mail in a form?

    Hi, I have a form that only has a few inputs, like Name, phone number and e-mail address. Now, if you type letters into the phone number input box and try to submit, it will recognize that you have not entered a valid phone number. But not the same for the e-mail address field. I just type in a few random letters, and it accepts it. Can someone please help?

    Here is my javascript code:

    Code:
    							function checkquotevalues(){
    								message="";
    								if(document.referaclient.name.value.length ==0){		
    										message = message+"Please enter a First Name.\n";
    								}	
    								
    								if(document.referaclient.areacode.value.length != 3 || document.referaclient.exchange.value.length != 3 || document.referaclient.phonenumber.value.length != 4){	
    									if(IsNumeric(document.referaclient.areacode.value) != 1	|| IsNumeric(document.referaclient.exchange.value) != 1 || IsNumeric(document.referaclient.phonenumber.value) != 1){
    										message = message+"Please enter a Numeric Phone Number.\n";
    										}
    										else { message = message+"Please enter a Phone Number.\n";}
    								}
    								else{ 
    									if(IsNumeric(document.referaclient.areacode.value) != 1	|| IsNumeric(document.referaclient.exchange.value) != 1 || IsNumeric(document.referaclient.phonenumber.value) != 1){
    									message = message+"Please enter a Numeric Phone Number.\n";
    									}
    								}
    								
    								if(document.referaclient.exchange.value == 555){
    									message = message+"Please enter a Valid Phone Number.\n";
    								}
    								
    								if (document.referaclient.Email.value.length ==0){
    										message = message+"Please enter your Email Address.\n";
    									}
    									else {
    									 	checkemail(document.referaclient.Email.value)
    									}	
    									
    								if(document.referaclient.businessname.value.length ==0){		
    										message = message+"Please enter a Business Name.\n";
    								}		
    								
    								if(document.referaclient.contactname.value.length ==0){		
    										message = message+"Please enter a Contact Name.\n";
    								}	
    								
    								if(document.referaclient.clientphonenumber.value.length ==0){		
    										message = message+"Please enter the Client's Phone Number.\n";
    								}	
    								
    								if (message.length > 0){	
    										alert(message);
    										return false;
    									}
    										
    											return true;
    								}
    				
    				
    				
    							function checkemail(str){
    								var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    								if (filter.test(str))
    								testresults=true
    								else{
    								message = message + "Email address seems incorrect (check @ and .'s)\n"
    								return false;
    								}
    								}
    
    							function IsNumeric(sText)
    								{
    								   var ValidChars = "0123456789";
    								   var IsNumber=true;
    								   var Char;
    								
    								 
    								   for (i = 0; i < sText.length && IsNumber == true; i++) 
    								      { 
    								      Char = sText.charAt(i); 
    								      if (ValidChars.indexOf(Char) == -1) 
    								         {
    								         IsNumber = false;
    								         }
    								      }
    									 return IsNumber;
    	   							}
    Here is a link to my .asp code: ASP page

    And, since the page is not up live, here is a screen shot of the code you're looking at:



    Thank you for any help you can give me!

  2. #2
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    118
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default

    Your javascript code does a bunch of checks and balances. Each one employs either an array of values to include or to exclude and cross-checks these arrays to return a value.

    The example below from your script checks the length of the email typed in. IF the email is equal to zero characters long (no input) the statement is true and runs the argument.

    Code:
    if (document.referaclient.Email.value.length ==0){
    message = message+"Please enter your Email Address.\n";
    }
    else {
    checkemail(document.referaclient.Email.value)
    }

    I did however detect in your checkemail() function a problem. Each variable declared should have opening and closing quotation marks " " and yours doesn't. var filter="whatever the characters to be parsed by another function in here"; is the correct format.



    Code:
    	function checkemail(str){  var filter="/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i"; 
    	
    if (filter.test(str)) 
    testresults=true
    Try that and see what happens.

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
  •