form email validation does not work

Discussion in 'PHP' started by renegades21, Jan 15, 2010.

  1. #1
    Hi
    I use the following form validation and it works all fine, except my email input does not get validated.

    Input type = email
    field name = emailto

    this is the code:
    function formCheck(formobj){
    	// Enter name of mandatory fields
    	var fieldRequired = Array("emailto","from", "emailfrom","zigi");
    	// Enter field description to appear in the dialog box
    	var fieldDescription = Array("Friends E-mail","Friends Name", "Your E-mail","Your Name");
    	// dialog message
    	var alertMsg = "These fields cannot be left blank:\n";
    
    	var l_Msg = alertMsg.length;
    
    	for (var i = 0; i < fieldRequired.length; i++){
    		var obj = formobj.elements[fieldRequired[i]];
    		if (obj){
    			switch(obj.type){
    			case "select-one":
    				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "select-multiple":
    				if (obj.selectedIndex == -1){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "text":
    			case "textarea":
    				if (obj.value == "" || obj.value == null){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				break;
    			case "email":
    				if (obj.value == "" || obj.value == null){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    				var strValue = emailto.obj.value; 
    				var strFilter = /^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i;
    				if (!strFilter.test(strValue))
    					alertMsg = "wrong or incomplete email" + fieldDescription[i] + "\n";
    				}
    				break;
    			default:
    			}
    			if (obj.type == undefined){
    				var blnchecked = false;
    				for (var j = 0; j < obj.length; j++){
    					if (obj[j].checked){
    						blnchecked = true;
    					}
    				}
    				if (!blnchecked){
    					alertMsg += " - " + fieldDescription[i] + "\n";
    				}
    			}
            }
       }
    	if (alertMsg.length == l_Msg){
    		return true;
    	}else{
    		alert(alertMsg);
    		return false;
    	}
    }
    
    PHP:
    What am I missing in the email validation, please?

    Thank a lot
     
    renegades21, Jan 15, 2010 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This is a javascript question not a PHP question
     
    JAY6390, Jan 15, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    danx10, Jan 15, 2010 IP
  4. renegades21

    renegades21 Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    OK thanks
    You may delete this post since I posted it new in the Javascript forum
     
    renegades21, Jan 15, 2010 IP