Jeff Davidson
Jeff Davidson

Reputation: 1929

Form Validation with Functions

I purchased a template that included many files and one of them was for jQuery form validation.

I'm using their template to create a register form. I also had created a validation code as well but what I would like to do is have my register form use the original validation code which is the script.js file. I would just need to figure out how I can use that script.js file with 6 different various forms like register, login, forgot password, etc. With just a little added code on each that's different like the success handler.

How can I do this?

Also included was the plugins.js file which includes how it can remove alert boxes which is nice not sure how I can use that function to remove the alert boxes on every form submission. How would I also with the form validation make it to where if an error message comes up for a specific input box and the focus is taken off of it then I want it to remove that error message.

Register Form

Upvotes: 1

Views: 214

Answers (1)

Nathan
Nathan

Reputation: 12000

Perhaps you would like to use the jQuery Form Validation Plugin? It's the best jQuery form validation plugin out there in my opinion. It's easy and you just add HTML classes and stuff to set the rules.

To set up the validator, it's simple as:

$('#form_id').validate();

Then, in the HTML you can add atributes like:

<form>
...
<label for="email">Email:</label><input type="text" class="required email" name="email" id="email" />
...
</form>

The class="required email" makes the plugin validate it as an email, and it makes it required. Also, if you add maxlength attribute, it'll make it only allow so many characters. You can also do minlength attributed and it'll limit the number of characters that must be entered. There's an example of the form that is in the link above.

Upvotes: 1

Related Questions