I have been researching on SO and applying suggestions but none seems to be addressing the issue here. I keep getting
"regexp.test is not a function"
based on the below. I have tried escaping @ with @@ and still getting the error message. Below is my script:
var dialog, form, dialog2,
emailRegex = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{0,4}$/,
FirstName = $("#FirstName"),
LastName = $("#LastName"),
Phone = $("#Phone"),
Email = $("#Email"),
allFields = $([]).add(FirstName).add(LastName).add(Phone).add(Email),
tips = $(".validateTips");
function checkRegexp(o, regexp, n) {
if (!(regexp.test(o.val()))) {
o.addClass("ui-state-error");
updateTips(n);
return false;
} else {
return true;
}
}
dialog = $("#dialog-form").dialog({
autoOpen: false,
height: 550,
width: 500,
modal: true,
buttons: {
"Apply": function () {
var valid = true;
allFields.removeClass("ui-state-error");
valid = valid && checkLength(FirstName, "First Name", 1);
valid = valid && checkLength(LastName, "Last Name", 1);
valid = valid && checkLength(Phone, "Phone", 1);
valid = valid && checkLength(Email, emailRegex, "Email must be valid");
valid = valid && checkRegexp(Email, "Email", 1);
if (valid) {
var url = '/contact/apply';
var formData = new FormData($("#formApply")[0]);
$.ajax({
url: url,
type: "POST",
data: formData,
enctype: 'multipart/form-data',
processData: false,
contentType: false,
success: function (data) {
if (data["hasApplied"]) {
dialog.dialog("close");
dialog2.dialog("open");
}
},
error: function () {
$(".validateTips").show().addClass("ui-state-error");;
updateTips("There was an error with your submission.");
}
});
}
},
Cancel: function () {
dialog.dialog("close");
}
},
close: function () {
$("#formApply")[0].reset();
allFields.removeClass("ui-state-error");
}
});
The emailRegex is not enclosed in quotes and it doesn't work when I escape the @.
Can anyone see anything that could be causing this function to fail?