This article mainly introduces how to judge the results of the validator. Here, let's look at how to implement a custom validator.
Goal
We want to implement a verification of the phone number of the validator, the use of the example or based on the previous article inside the example, that is, the user information entered the form page. We add a
It programmer development Essentials-all kinds of resources download list, history of the most IT resources, personal collection summary. These system validators are defined in the Default.xml under Com.opensymphony.xwork2.validator.validators in Xwork-2.x.jar:
the system provides the following validator:Required(Required validator, required field value cannot be null)requiredstring(A required String validator
HTML validator is an extension of Firefox. It is used for offline HTML syntax error checks. After installation, it can display in real time whether the compiled webpage meets the web standards.
HTML validator (for Windows ):
Https://addons.mozilla.org/zh-CN/firefox/addon/249
On Ubuntu 10.04, HTML validator is installed on Firefox 3.6 and cannot be use
The example in this article describes the validator validation extension usage in Laravel4. Share to everyone for your reference, specific as follows:
Whether you write the interface or write a Web page, the essence is passed in the parameters, and then the business logic, and then output the specific content. Therefore, the verification of the parameters is an inevitable link, such as the transmission over the email is not empty, is not a legitimate
Validator is a verification component in the jfinal framework. It provides common verification methods in the validator class, And validator implements the interceptor interface. Therefore, validator is equivalent to an interceptor. The specific usage is as follows:
For example, when logging on, check whether the user
The struts2 framework system has registered a built-in checker. You can open the xwork under the Lib package of struts2. jar package, find a default under the COM/opensymphony/xwork2/validator/validators directory. xml configuration file, which defines the built-in checker of the struts2 framework.From the struts2 configuration file, we can see that struts2 has the following built-in Checker:1 required: required. The field must have a value.Fieldname:
Why is it difficult to use the validate () method of actionform to verify user input data before validator is available?
1.The validator framework comesPrepackaged with several validation routines, making the transition fromHard-coded validation logic painless. (what isHard-coded validation logic? Is it that programmers do not have to write codeLine by line to perform validation ?) Instead of coding validat
Use async-validator to compile the Form component,
In front-end development, Form verification is a common function. Some ui libraries such as ant. design and Element ui both implement Form components with verification functions. Async-validator is a library that can perform asynchronous data verification. The ant. design and Element ui Form components both use async-va
First, the parameter checkIn development often need to write some field validation code, such as field non-empty, field length limit, mailbox format verification, and so on, write these and business logic does not relate to the code of the personal feeling there are two problems:
Verification code tedious, repetitive labor
The code in the method looks verbose
Each time you want to see which parameter verification is complete, you need to go through the Verification logic code
Because the code is relatively simple and less annotated, it is mainly used to verify simple rules (you can also add Regular Expressions by yourself if you have built-in ones, and complex methods are not supported at the moment ), it also handles the verification during form submission. The main idea is to follow a previously jQuery-based validator plug-in. The following is the js Code (it is not elegant when binding objects. I hope you can give me so
Kernel Authenticator core validators0. PrefaceYII provides a series of Common Core validators that you canFound in yii\validators namespace . Instead of using long validator class names, you can replace them with aliases.For example, you can use alias required instead of the Yii\validators\requiredvalidator class:this yii\validators\validator:: $builtInValidators attribute the alias of all supported validat
":
The code is as follows
Copy Code
Type= "number" typetip= ' Min= "mintip=" can not be less than 10 years old " max= "maxtip=" Are you still alive? >
Verify email, url, date
You can use the Reg property to make validation more powerful, and you can use several regular expressions preset in $.panzer.reg to determine the format of mailboxes:
Validator verification framework
The validator framework can overcome the limitations of programming data verification in actionform bean. It allows struts to apply flexible configuration verification rules without programming.
The validator framework mainly depends on two jar files: jakarta-oro.jar and commons-validator
I learned validator today. One method in actionform is validate (), which can be used to write verification code. But the disadvantage is that if I have a lot of actionforms, I don't want to write them to the dead. Therefore, the dynamic form (dynaactionform) appears, but it must be verified based on the dynamic form. This is troublesome.
Validator was created by David winterfeldt and can be integrated into
We are doing some operations are required to verify the user's input data, such as the registration of the site, the need for data validation of individual data items, STRUTS2 provides some default validators, such as digital detection, mailbox detection, string length detection and so on.
The Common validator
Checker
Role
Required
Required validator, req
Bean Validation class library comparison
Recently, when I was writing a project, I wanted to add the Bean Property Verification, just as there was a verification for each value in Domain in Grails. However, the workload for writing beautiful data by yourself is not small, and some people may have done this basic job. After checking on the Internet, we found the jsr303 standard, and there was a very mature implementation class library. After reading the circle, there are three better ones: Hibern
Verification Framework-based input verification
1. Create a struts2 project testValidators. Struts2 Initial Experience: http://www.cnblogs.com/likailan/p/3280820.html
Registration page, register. jsp:
Use
Use the
Registered Email: Password: Repeated password: Phone:
Registered successfully
The fields to be verified must provide the corresponding fields and the corresponding get and set methods in the class.
RegisterAction String execute()
The following is the js Code (it is not elegant when binding objects. I hope you can give me some advice !)Copy codeThe Code is as follows:Function validator (obj, option) {// verification objectVar self = this;If (! (Self instanceof validator ))Return new validator (obj, option );Self. source = {'mobile': '^ (13 | 14 | 15 | 18) [0-9] {9} $', 'postcode ': '^ \ d
The following is the JS code (in the binding object when the feeling is not elegant, I hope the expert can guide twos Ah!) )
Copy Code code as follows:
Function Validator (obj,option) {//Authentication object
var self = this;
if (!) ( Self instanceof Validator))
return new Validator (obj,option);
self.source={' mobile ': ' ^ (13|14|15|18) [0-9]{9
1 defines the validator interface under the Com.opensymphony.xwork2.validator package.Public interface ValidatorValidator is divided into two main categories:Plain validators and fieldvalidators.The validators come in both different flavors:a) Plain Validators/non-field VALIDATORSB) fieldvalidatorsThis article mainly discusses the differences between the two validator
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.