在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:posabsolute/jQuery-Validation-Engine开源软件地址:https://github.com/posabsolute/jQuery-Validation-Engine开源编程语言:JavaScript 98.5%开源软件介绍:jQuery.validationEngine v3.1.0Looking for official contributorsThis 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. SummaryjQuery 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 documentionRelease NotesInstallationWhat's in the archive?Download 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).
UsageReferencesFirst include jQuery on your page <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 <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 <link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/> Field ValidationsValidations are defined using the field's class attribute. Here are a few examples showing how it happens: <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-engineWe 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 messageCustomize error messages with data-errormessage and data-errormessage-* attributes on the form elements. For example: <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
data-errormessage-type-mismatch
data-errormessage-pattern-mismatch
data-errormessage-range-underflow
data-errormessage-range-overflow
data-errormessage-custom-error
data-errormessage
Per Field Prompt DirectionPrompt direction can be define using the field's data attribute. Here are a few examples showing how it happens: <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 AdjustmentPrompt 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: <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" /> InstantiationThe validator is typically instantiated with a call in the following format, the plugin can only be instanciated on form elements: $("#form.id").validationEngine(); Without any parameters, the init() and attach() methods are automatically called. $("#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: <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: <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. <script>
$(document).ready(function(){
$("#formID").validationEngine('attach', {promptPosition : "centerRight", scroll: false});
});
</script> All calls to validationEngine() are chainable, so one can do the following: $("#formID").validationEngine().css({border : "2px solid #000"}); ActionsattachAttaches jQuery.validationEngine to form.submit and field.blur events. $("#formID1").validationEngine('attach'); detachUnregisters any bindings that may point to jQuery.validaitonEngine. $("#formID1").validationEngine('detach'); validateValidates a form or field, displays error prompts accordingly. 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. // 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:
<fieldset>
<legend id="legendid">Email</legend>
<a href="#" onclick="$('#legendid').validationEngine('showPrompt', 'This a custom msg', 'load')">Show prompt</a>
</fieldset> hideThe hide method can be applied to a form or a field. // closes all form prompts
$('#formID1').validationEngine('hide');
// closes onle one prompt
$('#email1').validationEngine('hide'); hideAllCloses/hides all error prompts on the page no matter what form they are attached to. $('#formID1').validationEngine('hideAll'); updatePromptsPositionUpdate the form prompts positions. $("#formID").validationEngine("updatePromptsPosition") hidePrompt & validateFieldDeprecated and not part of the code base anymore. OptionsOptions are typically passed to the init or attach action as a parameter. $("#formID1").validationEngine({promptPosition : "centerRight", scroll: false});
$("#formID1").validationEngine('attach', {promptPosition : "centerRight", scroll: false}); validationEventTriggerName of the event triggering field validation, defaults to blur. scrollDetermines if we should scroll the page to the first error, defaults to true. bindedIf set to false, it removes blur events and only validates on submit. promptPositionWhere should the prompt show? Possible values are "topLeft", "topRight", "bottomLeft", "centerRight", "bottomRight". Defaults to "topRight". Default position adjustment could also be provided. showOneMessageOnly 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. ajaxFormValidationIf 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. ajaxFormValidationURLIf set, the ajax submit validation will use this url instead of the form action ajaxFormValidationMethodHTTP 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. onValidationCompleteWhen 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. jQuery("#formID2").validationEngine('attach', {
onValidationComplete: function(form, status){
alert("The form status is: " +status+", it will never submit");
}
}); custom_error_messagesThis 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: jQuery("#formID2").validationEngine({'custom_error_messages' : {
'#someId' : {
'required': {
'message': "This is a custom message that is only attached to the input with id 'someId' if it
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论