// validate email function, after function other code relative to its use // function validateEmail(x) { var tld=""; console.log(x); var splitAt = x.split("@"); if(!splitAt[1]) {return false;} var username = splitAt[0]; var domainTLD = splitAt[1].split("."); var domain=domainTLD[0]; for(var i=1;i<5;i++) { if(domainTLD[i]) { console.log(i +" "+ domainTLD[i]); tld=domainTLD[i] ;} } var usernameLength = username.length; var domainLength = domain.length; var tldLength = tld.length; msg=username; console.log(msg); msg=domain; console.log(msg); msg=tld; console.log(msg); msg=usernameLength; console.log(msg); msg=domainLength; console.log(msg); msg=tldLength; console.log(msg); if ( tldLength < 3 || tldLength > 3 || domainLength < 2 || usernameLength < 1 || /\d/.test(tld) ) { console.log(x + " not a valid e-mail address"); return false; } else { return true; } } // just some vars not pertinent to email validation var timedFade = 1000; var msg=""; // document ready code block below $(document).ready(function(){ msg="document.ready"; console.log(msg); msg=""; $( "#email" ).blur(function() { var email=$( "#email" ).val(); console.log(email); if (validateEmail(email)) { console.log("good email"); $("#email-status-message").text(""); $("#email-status-message").fadeOut(timedFade); } else { console.log("bad email"); $("#email-status-message").text("please enter valid email"); $("#email-status-message").fadeIn(timedFade); } }); })
Friday, October 18, 2013
Validate email with jQuery and my own hack
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment