samoi Posted February 28, 2010 Share Posted February 28, 2010 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 ! Quote Link to comment Share on other sites More sharing options...
salathe Posted February 28, 2010 Share Posted February 28, 2010 Remove the single quotes (') from your filter. Quote Link to comment Share on other sites More sharing options...
samoi Posted February 28, 2010 Author Share Posted February 28, 2010 Remove the single quotes (') from your filter. Nothing happened! but thanks anyway! Quote Link to comment Share on other sites More sharing options...
salathe Posted February 28, 2010 Share Posted February 28, 2010 "Nothing happened!" is not much use to anyone. What does your logging say? Quote Link to comment Share on other sites More sharing options...
samoi Posted February 28, 2010 Author Share Posted February 28, 2010 "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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.