1. What is jsvalidation?
As stated on the homepage, jsvalidation is a form verification framework on the client, which is used in BS systems or simple web systems. Form Verification is common in these development scenarios: New User Registration requires validation of certain fields;
User Login, verification required; and so on. Before that, page developers (JavaScript developers) need to write a large amount of JavaScript to interact with form objects and perform verification.
Common verification, such as cannot be blank, must meet the length requirements, must be a number, must be an email, and so on. Based on general experience, if the number of fields to be verified in a form exceeds 10,
The development process seems boring-repeated code in multiple sections is constantly repeated. If cross-browser is required, more considerations are a headache. Often the verification on this page cannot be used for that verification ...... Although the logic is basically the same;
But in most cases, for various reasons, developers would rather (or cannot) rewrite JavaScript code for another page.
Jsvalidation is committed to improving this process. It encapsulates common verifications (currently supports 13 types) and creatively uses XML to store form verification information, making form verification the least important part of the project,
Developers only need to define several XML tags to create complex authentication policies without writing a line of JavaScript code. Because XML is used to centrally manage form verification, the coupling degree of Form Verification in the entire system is greatly reduced,
It is also easy to maintain and greatly improves. Developers can devote more energy to business-related code.
On the contrary, although the internal structure of jsvalidation is not very simple (for users), the call method is extremely simple. After the environment is configured, you only need to add it to the HTML tag of the form to be verified.
Onsubmit = "Return dovalidate ('formid. This does not change the developer's habits.
The more obvious advantage is that jsvalidation is capable of cross-browser access. In the current test environment, ie5 and later versions are supported, Mozilla series and other browsers that support the dom2 model.
You don't have to worry about compatibility in multiple browsers. jsvalidation helps you do this.
2. What can jsvalidation do and cannot do?
As mentioned above, jsvalidation can verify the form. In scenarios with complex systems and complex forms, jsvalidation has more advantages. Currently, jsvalidation can complete the following 13 types of client Verification:
The value is not empty.
Must be an integer
The value must be double-precision.
Must be a regular English character (letter, number, underline)
Must be a Chinese character
Minimum Length
Maximum length
Is it in email format?
Date Format (yyyy-mm-dd)
Custom Regular Expression
Integer Range (greater than a certain number and smaller than a certain number)
Double Precision range
Must be the same as the value of a domain
All these verifications are completed on the client. If there are other verification requirements, please let us know, we will develop a new verification model based on the degree of demand.
Jsvalidation cannot do the following:
Cross-page verification. For example, the value entered on page a must meet the condition of a value on page B or more pages. This requirement requires user feedback. If such requirements are common in real development, we will consider development.
Currently, the alternative is to post the value to be verified on page A to a hidden field on page B, and then use the existing authentication method.
Verify interaction with the server. The most common is to enter the user name and password and then log on. Due to its representation range, jsvalidation cannot complete this task.
I hope you can tell us what you haven't mentioned.
3. Under what circumstances should I use jsvalidation?
The answer is, if there is no existing verification reference, use it.
Many development tools and development frameworks (models) have provided verification support, such as ASP. NET and struts. However, more frameworks are not supported, such as the velocity
(Maybe it cannot be called a framework), as well as other ASP, PHP, pure JSP, CGI, and so on. There may be no mature framework to use. If not, jsvalidation may help you relieve the pressure on the client to verify programming,
This gives you more energy to focus on your business.
In addition, if your system is small or requires very little verification-for example, if only one login user name and password need verification, we do not recommend jsvalidation based on performance considerations.
The jsvalidation library file reaches 22 KB. With the verification file added, you may need to load an additional 26 KB + on your page to run the file. For the same function, you can write only a few lines in the regular mode.
Of course, if you already have your own model in the development process, you will be familiar with it and be very strong. Try your best to use your own method. Jsvalidation is not tested over time (before v1.0b ).
4. Quick Start
You can get started quickly (see the effect) in two ways)
View the demo page directly (goto>)
Download the latest version and view it locally. (Goto>)
In either way, the detailed steps and corresponding code are provided in the demo.
5. Procedure
The following describes how to configure jsvalidation in actual development. Before starting these steps, make sure that you have downloaded the latest jsvalidation-framework.js file.
5.1 configure the environment
First copy the jsvalidation-framework.js and validation-config.xml to a directory on the site, such as/javascripts.
Open the jsvalidation-framework.js and find var validationroot = ""; change this line of code to VaR validationroot = "/javascripts/"; (that is the location of the validation-config.xml file ).
Add the reference of jsvalidation to the page for verification:
<Script language = "JavaScript" src = "/javascripts/jsvalidation-framework.js"> </SCRIPT>
Add on submit = "Return dovalidate ('formid ')" to the Form tag to be verified on this page ')". Formid is the ID of the form.
Complete.
5.2 write validation-config.xml
The validation-config.xml is the place where the form is centrally managed and the validation conditions are processed by jsvalidation.
-File Format
The validation-config.xml is in standard text format. You can edit it in any text editor. Before the verification, make sure that your xml file is properly displayed in the browser.
-Basic Structure
<Validation-config> Each validation-config.xml has a validation-config Root Node
<Form...> one or more forms can be verified.
<Field...> Each form has one or more form fields to be verified.
<Depend.../> one or more conditions must be verified for each domain.
-Node description
Validation-config: Root Node
Attribute: Lang: the language used. It can be "Auto", "ZH-CN" (Simplified Chinese), or "En-us" (English ). The default value is auto. Optional.
Subnode: form, one or more
Form: virtual form, which maps the form in the webpage by ID
Property: ID: ing the ID in the webpage form. Through this ID, jsvalidation is associated with the actual webpage table. Required
Show-error: how to display the error message. It can be alert (the dialog box will be displayed) or a div ID (which will be
Error messages are displayed in each Div.) required.
Onfail: a custom JS function that runs when verification fails. Optional (not implemented in this version)
Subnode: field, one or more
Field: virtual form field, which maps the actual fields in the form by name
Attribute: Name: name of the field in the form, for example, input name = "ABC". Here, it corresponds to ABC. Required
Display-Name: Display name of the form. This attribute is displayed when verification fails. Required
Onfaile: Same as onfail in form. Not implemented yet. Optional
Subnode: depend, one or more
Depend: Check Condition
Attribute: Name: the name of the validation condition. It must be one of the names specified in the following 13 and is case sensitive. Required.
Param0-param4, five parameters, according to different names, each has different values.
Example:
<! -- Verify login, simple. For complex examples, see demo -->
<Validation-config>
<Form ID = "loginform" show-error = "alert" onfail = "">
<Field name = "username" display-name = "username" onfail = "">
<Depend name = "required"/>
<Depend name = "commonchar"/>
</Field>
<Field name = "password" display-name = "password" onfail = "">
<Depend name = "required"/>
</Field>
</Form>
</Validation-config>
5.3 Verification Form
After writing the validation-config.xml, you can deploy according to the above deployment method.
6. 13 types of verification supported by jsvalidation