views:

304

answers:

2

I'm trying to build a sign-up form that will only accept .EDU e-mail addresses. I also want to keep the AJAX functionality I have (using the "remote" parameter) to ensure that the e-mail address hasn't been used before.

How can I do this?

+1  A: 

Nevermind - figured it out!

Just had to use jQuery.validator.addMethod to create a function to check the substring of the last 3 letters, leaving my other code intact, and add a class referring to the added method in my HTML.

+3  A: 
$.validator.addMethod("edu-email", 
    function(value) {
        return (value.endsWith(".edu"));
    },
    "e-mail address must end in .edu."
);

JavaScript doesn't have a string.endsWith. You'll have to add your own.

Now add "edu-email" to the form input class.

Craig Stuntz