Inside your blur handler, you declare a function. Declare your function outside this handler and call it inside your handler.
function validateEmail(studentEmail){ var emailReg = /^([\w-\.] +@ ([\w-]+\.)+[\w-]{2,4})?$/; if(!emailReg.test(studentEmail)) { alert("Please enter valid email id"); } } $("#studentEmail").blur(function() { alert ("test1"); validateEmail($(this).val()); });
Or, if this function has zero reuse, you can simply do this:
$("#studentEmail").blur(function() { alert ("test1"); var emailReg = /^([\w-\.] +@ ([\w-]+\.)+[\w-]{2,4})?$/; if(!emailReg.test($(this).val())) { alert("Please enter valid email id"); } });
source share