As a non-developing open source project, Struts uses the Validate of Jakarta's Commons project, combined with the Struts's MVC system, which is really good. It is recommended to check this part after completing the JSP. Principle: Struts' page school test score, one is the front desk generating JavaScript, one is the background class. ????? The error message corresponds to two display methods, one is a pop-up message box, one is displayed at the original page. ????? I personally prefer to pop up the message box, because you can set the focus to the error of the error. ????? So I focus on how to implement this. ????? Please follow the steps step by step, think about it. ????? 1 ???? Put the Struts required to join the project lib path or server LIB path ????? Struts1.1 needs to use the LIB: struts-legacy.jar struts.jar Jakarta-oro.jar Commons-validator.jar ????? Commons-logging.jar Commons-lang.jar Commons-fileupload.jar Commons-Digester.jar Commons-Collections.jar ????? Commons-beanUtils.jar (you can see Struts1 .1 Use a lot of Commons project stuff) 2 ???? Put the value of the value.xml and validator-rules.xml ???? in the WebApps / Struts-Validator.war of the Struts1.1 package. To the project's Web-INF path ????? Carefully study these two files, you can see that validator-rules.xml is to provide some common Validation rules. ????? Currently provided Required, Requiredif, MINLENGTH, MAXLENGTH, MASK, BYTE, SHORT, INTEGER, Long, Float, ????? Double, Date, Range, IntRange, FloatRange, Creditcard, Email, ??? ?? I saw it, only Mask didn't know if it was dry, other words. (As for how DIY's own Rule, I will not be) ????? The head play, modify validation.xml. You can take a look at the validation.xml structure validation.xml: ?????
????????? "- // Apache Software Foundation // DTD Commons Validator Rules Configuration 1.0 // En" ????????? "http://jakarta.apache.org/commons/ DTDS / VALIDATOR_1_0.DTD ">
??
?????
???????
Phone
???????
^ / (? (/ d {3}) /)? [- |]? (/ d {3}) [- |]? (/ d {4}) $
?????
?????
???????
zip
???????
^ / d {5} / d * $
?????
??
??
?????
???????
zip
???????
^ / d {5} (- / d {4})?
?????
?????
????????
???????? ??? depends = "Required, Mask, MINLENGTH">
?????????????
?????????????
????????????????????
??????????????????????
Mask
??????????????????????
^ / W $
?????????????????????????????????
??????????????????????
MINLENGTH
??????????????????????
5
????????????????????
????????
??????? ..........
??????
????? I believe that everyone will understand carefully, first, some rules expressed in regular expressions, these rules are also divided into globally and partial.
????? This can be DIY some rules that can be represented by regular expressions, such as the specific use of custom rules below: Phone.
????? ...
??
?????
???????
Phone
???????
^ / (? (/ d {3}) /)? [- |]? (/ d {3}) [- |]? (/ d {4}) $
?????
??
?? ...??
?????
???????? ??? depends = "mask">
?????????????
????????????????????
??????????????????????
Mask
??????????????????????
$ {phone}
????????????????????
?????
?? ...
????? This also understands Mask's role, it turns out that it is specifically used for custom rules!
????? Then you can add the field that needs to be added to Validation, the format is as follows:
?????
?????