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 !

Link to comment
Share on other sites

"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!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.