I am in a situation where I cant use the validate plugin of Jquery.
So I have written a custom validator. But the test function is not working for some reason.
Code is running fine till the line if (format.test(email)) { . Please share your knowledge. Thanks in advance
$(document).ready(function () {
$("#MainContent_btnSubmit").click(function () {
validateEmail();
});
});
function validateEmail() {
var format = "[a-zA-Z._0-9]@[a-zA-Z.0-9].[a-zA-Z]";
var email = $("#MainContent_txtEmail").val();
if (format.test(email)) {
alert("Correct Email");
}
else {
alert("Wrong Email");
}
formatneeds to be aRegExpobject:Additionally, I suspect you want the value to contain nothing but an email, so use anchors: