Jump to content

filter.test(value) isn't working! please help me out!


samoi

Recommended Posts

Hello!

I am trying to validate name, email  and comment inputs!

I did the following!

			$("#CmtSub").click(function(event){
                                var email = $("#CmtEmail").val();
                                var filter = /'^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$'/;
                                
			            
                                if( $("#CmtName").val() == "" ){
							    $("#CmtName").css({'background-position': '0 -45px'}, 0);
							    return event.preventDefault(event);
							}else{
							    $("#CmtName").css({'background-position': '0 -90px'}, 0);
							}


                                if(filter.test(email) && email != "") {
                                
                                    $("#CmtName").css({'background-position': '0 -45px'}, 0);
                                    return event.preventDefault(event);
                                    }else{
                                        
                                        $("#CmtName").css({'background-position': '0 -90px'}, 0);
                                    }


                                //just to debug
                                console.log("the value and the email ("+ email +")");
                                
                                if( $("#CmtTxtArea").val() == "" ){
								$("#CmtTxtArea").css({'border': 'red 1px solid'}, 0);
								return event.preventDefault(event);
							}else{
		                         $("#CmtTxtArea").css({'border': 'white 1px solid'}, 0);
							}



// then proceed !



});

 

this code here isn't working! any help please ?:

                                if(filter.test(email) && email != "") {
                                    //passme = false;
                                    $("#CmtName").css({'background-position': '0 -45px'}, 0);
                                    return event.preventDefault(event);
                                    }else{
                                        //passme = true;
                                        $("#CmtName").css({'background-position': '0 -90px'}, 0);
                                    }

 

help is greatly appreciated !

"Nothing happened!" is not much use to anyone. What does your logging say?

Oh I am so sorry my friend!

I apologize

it worked with else if statement ! it's crazy I know but this is what happened!

 

                                var email = $("#CmtEmail").val();
                                var filter = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/;
                                var passme = false;
                                var num = 1;
                                
                                if(email == ""){
                                    passme = false;
							    $("#CmtEmail").css({'background-position': '0 -45px'}, 0);
							    return event.preventDefault(event);
							}else if(!filter.test(email)){
							    passme = false;
                                    num = 2;
							    $("#CmtEmail").css({'background-position': '0 -45px'}, 0);
							    return event.preventDefault(event);
							}else{
							    passme = true;
							    $("#CmtEmail").css({'background-position': '0 -90px'}, 0);
							}



                                
                                console.log( passme + " the value and the email ("+ email +") and "+ num);

 

I really appreciate your help!

Thank you thank you thaaaaaaank you the most thanks!

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.