0

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?

1
  • Hilarious!! Totally needed a new set of eyes. Thank you! If you add this as an answer, I can mark it. Commented Jul 17, 2015 at 17:44

1 Answer 1

1

It looks like you accidentally mixed up the parameters in your checks:

// Passes Regex
checkLength(Email, emailRegex, "Email must be valid");

// Doesn't Pass Regex
checkRegexp(Email, "Email", 1);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.