Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
J

jQuery-Validation-Engine

> 编程语言
Open source

jQuery form validation plugin

2.5K stars0 likes1 views
WebsiteGitHub

About

jQuery form validation plugin

jQuery.validationEngine v3.1.0

Looking for official contributors

This project has now been going on for more than 7 years, right now I only maintain the project through pull request contributions. However, I would love to have help improving the code quality and maintain an acceptable level of open issues.

Summary

jQuery validation engine is a Javascript plugin aimed at the validation of form fields in the browser (IE 6-8, Chrome, Firefox, Safari, Opera 10). The plugin provides visually appealing prompts that grab user attention on the subject matter.

Validations range from email, phone, and URL, to more complex calls such as ajax processing or custom javascript functions. Bundled with many locales, the error prompts can be translated into the language of your choice.

Documentation :

Nicer documention

Release Notes

Installation

What's in the archive?

Download

tar.gz 3.0.0 or zip 3.0.0

The archive holds, of course, the core library along with translations in different languages. It also comes with a set of demo pages and a simple ajax server (built in Java and php).

  1. Unpack the archive
  2. Include the script jquery.validationEngine.closure.js in your page
  3. Pick the locale of the choice and include it in your page: jquery.validationEngine-XX.js
  4. Read this manual and understand the API

Usage

References

First include jQuery on your page

xml
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" type="text/
javascript"></script>

Include jquery.validationEngine and its locale

xml
<script src="js/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>

Finally include the desired theme

xml
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>

Field Validations

Validations are defined using the field's class attribute. Here are a few examples showing how it happens:

xml
<input value="[email protected]" class="validate[required,custom[email]]" type="text" name="email" id="email" />
<input value="2010-12-01" class="validate[required,custom[date]]" type="text" name="date" id="date" />
<input value="too many spaces obviously" class="validate[required,custom[onlyLetterNumber]]" type="text" name="special" id="special" />

For more details about validators, please refer to the section below.

Experimental attribute data-validation-engine

We are currently in the process of replaceing the class attribute by something more standard, it should normally work but consider this feature in beta.

Standard HTML5 attribute for error message

Customize error messages with data-errormessage and data-errormessage-* attributes on the form elements. For example:

xml
<input type="email" name="email" id="email" data-validation-engine="validate[required,custom[email]]"
	data-errormessage-value-missing="Email is required!" 
	data-errormessage-custom-error="Let me give you a hint: [email protected]" 
	data-errormessage="This is the fall-back error message."/>

The following attribute's value will be loaded for the relative validation rule:

data-errormessage-value-missing
  • required
  • groupRequired
  • condRequired
data-errormessage-type-mismatch
  • past
  • future
  • dateRange
  • dateTimeRange
data-errormessage-pattern-mismatch
  • creditCard
  • equals
data-errormessage-range-underflow
  • minSize
  • min
  • minCheckbox
data-errormessage-range-overflow
  • maxSize
  • max
  • maxCheckbox
data-errormessage-custom-error
  • custom
  • ajax
  • funcCall
data-errormessage
  • a generic fall-back error message

Per Field Prompt Direction

Prompt direction can be define using the field's data attribute. Here are a few examples showing how it happens:

xml
<input value="http://" class="validate[required,custom[url]] text-input" type="text" name="url" id="url" data-prompt-position="topLeft" />
<input value="" class="validate[required] text-input" type="text" name="req" id="req" data-prompt-position="bottomLeft" />
<input value="too many spaces obviously" class="validate[required,custom[onlyLetterNumber]]" type="text" name="special" id="special" data-prompt-position="bottomRight" />

Prompt Position Adjustment

Prompt position can be adjusted by providing shiftX and shiftY with position type in the field's data attribute. Prompt will be placed in (defaultX+shiftX),(defaultY+shiftY) position instead of default for selected position type. Here are a few examples showing how it happens:

xml
<input value="http://" class="validate[required,custom[url]] text-input" type="text" name="url" id="url" data-prompt-position="topLeft:70" />
<input value="" class="validate[required] text-input" type="text" name="req" id="req" data-prompt-position="bottomLeft:20,5" />
<input value="too many spaces obviously" class="validate[required,custom[onlyLetterNumber]]" type="text" name="special" id="special" data-prompt-position="bottomRight:-100,3" />

Instantiation

The validator is typically instantiated with a call in the following format, the plugin can only be instanciated on form elements:

javascript
$("#form.id").validationEngine();

Without any parameters, the init() and attach() methods are automatically called.

javascript
$("#form.id").validationEngine(action or options);

The method may take one or several parameters, either an action (and parameters) or a list of options to customize the behavior of the engine.

Here's a glimpse: say you have a form as such:

xml
<form id="formID" method="post" action="submit.action">
    <input value="2010-12-01" class="validate[required,custom[date]]" type="text" name="date" id="date" />
</form>

The code below will instantiate the validation engine and attach it to the form:

xml
<script>
$(document).ready(function(){
    $("#formID").validationEngine();
   });
</script>

When using options, the default behavior is to only initialize ValidationEngine, so attachment needs to be done manually.

xml
<script>
$(document).ready(function(){
    $("#formID").validationEngine('attach', {promptPosition : "centerRight", scroll: false});
   });
</script>

All calls to validationEngine() are chainable, so one can do the following:

javascript
$("#formID").validationEngine().css({border : "2px solid #000"});

Actions

attach

Attaches jQuery.validationEngine to form.submit and field.blur events.

javascript
$("#formID1").validationEngine('attach');

detach

Unregisters any bindings that may point to jQuery.validaitonEngine.

javascript
$("#formID1").validationEngine('detach');

validate

Validates a form or field, displays error prompts accordingly.
Returns true if the form validates, false if it contains errors.

For fields, it returns false on validate and true on errors.

When using form validation with ajax, it returns undefined , the result is delivered asynchronously via function options.onAjaxFormComplete.

javascript
// form validation
alert( $("#formID1").validationEngine('validate') );

// field validation
alert( $("#emailInput").validationEngine('validate') );

showPrompt (promptText, type, promptPosition, showArrow)

Displays a prompt on a given element. Note that the prompt can be displayed on any element by providing an id.

The method takes four parameters:

  1. the text of the prompt itself
  2. a type which defines the visual look of the prompt: 'pass' (green), 'load' (black) anything else (red)
  3. an optional position: either "topLeft", "topRight", "bottomLeft", "centerRight", "bottomRight". Defaults to "topRight"
  4. an optional boolean which indicates if the prompt should display a directional arrow
xml
<fieldset>
   <legend id="legendid">Email</legend>
   <a href="#" onclick="$('#legendid').validationEngine('showPrompt', 'This a custom msg', 'load')">Show prompt</a>
</fieldset>

hide

The hide method can be applied to a form or a field.
It closes/hides error prompts.

javascript
// closes all form prompts
$('#formID1').validationEngine('hide');

// closes onle one prompt
$('#email1').validationEngine('hide');

hideAll

Closes/hides all error prompts on the page no matter what form they are attached to.

javascript
$('#formID1').validationEngine('hideAll');

updatePromptsPosition

Update the form prompts positions.

javascript
$("#formID").validationEngine("updatePromptsPosition")    

hidePrompt & validateField

Deprecated and not part of the code base anymore.
Use hide and validate instead.

Options

Options are typically passed to the init or attach action as a parameter.

javascript
    $("#formID1").validationEngine({promptPosition : "centerRight", scroll: false});
    $("#formID1").validationEngine('attach', {promptPosition : "centerRight", scroll: false});

validationEventTrigger

Name of the event triggering field validation, defaults to blur.

scroll

Determines if we should scroll the page to the first error, defaults to true.

binded

If set to false, it removes blur events and only validates on submit.

promptPosition

Where should the prompt show? Possible values are "topLeft", "topRight", "bottomLeft", "centerRight", "bottomRight". Defaults to "topRight". Default position adjustment could also be provided.

showOneMessage

Only display the first incorrect validation message instead of normally stacking it. It will follows the validation hierarchy you used in the input and only show the first error.

ajaxFormValidation

If set to true, turns Ajax form validation logic on. Defaults to false. Form validation takes place when the validate() action is called or when the form is submitted.

ajaxFormValidationURL

If set, the ajax submit validation will use this url instead of the form action

ajaxFormValidationMethod

HTTP method used for ajax validation, defaults to 'get', can be set to 'post'

onBeforeAjaxFormValidation(form, options)

When ajaxFormValidation is turned on, this is the function that will be called before the asynchronous AJAX form validation call. May return false to stop the Ajax form validation

onAjaxFormComplete: function(status, form, errors, options)

When ajaxFormValidation is turned on, this function is used to asynchronously process the result of the validation. the status is a boolean. If true, the ajax call completed and all the server side form validations passed.

onValidationComplete

When defined, it stops by default the form from auto-submitting, and lets you handle the validation status via a function. You can also return true in this function and the form will be allowed to submit.

javascript
jQuery("#formID2").validationEngine('attach', {
  onValidationComplete: function(form, status){
    alert("The form status is: " +status+", it will never submit");
  }  
});

custom_error_messages

This is where custom messages for IDs, Classes, or validation types are stored.

Custom error messages are exclusive from one another.ID messages will be displayed instead of anything else; Class messages will only be used if there is no ID message, and only the first message found associated with one of the classes will be used; Global Validator messages will only be used if there are no Class messages or ID messages.

These custom messages are declared in this manner:

…

focusFirstField

Specifies whether or no

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言