Apply Mask Validator Rule on Form Bean Property

In validation.xml to apply mask validator rule on form bean property (user name):-

In my file properties


More Regular Expressions for form validation:-

Limitation with mask validator rule:-

  1. This validator rule is not working on specific form components like text area and etc.(working properly with textbox & problem is there with client side javascript execution)
  2. Programmer cannot write the form validation logic of mask validator rule by using multiple form bean properties data that means the following form validation logic are not possible with mask validator.

a)      Checking whether password & confirm passwords are matching or not.

b)      Checking whether username & password are beginning with same character or not and etc.

  1. Working with Regular Expression takes time to habituate.
  • Procedure to modify the port number of glassfish & s/w that comes with Net beans IDE installation (for domain 1 server):—-

– Go to Glassfish-home\AppServer\domain1\config\folder à open domain.xml file

-Modify port attribute value of <http-listener> tag available in line n0. 61

  • To solve the problems of approach no.(1) (mask validation rule) use approach no.(2) calling super.validate() from our validate (-) method of form bean class and calling validator plug-in generated dynamic javascript function from user defined javascript function of form page.

Note:-  Our validate () of form bean class performs programmatic server side form validations.

  • Our javascript function of form page performs programmatic client side form validations.
  • The validator plug-in generated dynamic javascript function performs declarative client side form validations.
  • Approach no. (2) is very much recomanded to write programmatic form validation logic based on the data of multiple form bean properties.
  • Procedure to perform formvalidations based on approach no. (2) to mix-up our form validation logic with the validator plug-in based form valadition at client side to serverside (with respect to StrutsDemoApp1-DV application).

Step1:– override validate () in our form bean class calling super.validate () and also by having programmatic server side form validation ligic.

In registerForm, java



Step2: add additional form validation error message in properties file.


          My.unped.len = username & password must have same length.

Step3: – Add user defined javascript function in form page having client side programmatic validation logic and also calling the validator plug-in generated dynamic javascript function.

In register.jsp:-

Step4:– develop the remaining resources of the application manually.

  • The mask validator rule (approach no. (1)) is specific to one form bean property on which it is applied.
  • The approach no. (2) form validation logic is specific to single form page/ single form bean class.
  • To solve approach (1) & approach (2) limitations use approach (3) which allows to add custom validator rule in vaidator plug-in.

Note: – Validator rule of the validator plug-in is visible in all form pages/ form bean classes of Struts application.

Approach no. (3):- adding custom vaidator rule can be defined having both java & javascript code to perform client side & server side form validations. This validator rule can use only one form bean property data at a time to perform form validation use approach (3) to give Struts app. Level global visibility to your form validation logic.

  • Procedure to add custom vaidator rule to validator plug-in of (checking whether first character & last character of form bean property value) is same or not:-

Step (1):- Define default error message for custom vaidator rule in properties file. (With respect



My.custrule.msg = {0} must contain same first & last character.

Step2:-configure cust validator rule in validator-rules.xml file having logical name

In WEB-INF\ validator-rules.xml:- 

Step5:-  add satya validateSatyaRule.js file in WEB-INF\classes folder having custom form validation logic for SatyaRule. (javascript code).   

            ValidateSatyaRule.js (develop this file based on other.js file of commons validator-1.3.1.jar file)

Step6:- apply this SatyaRule on username property of form bean class.

In validation.xml:-


Step7:- develop the remaining resources of the applications in regular manner.

Note: – We can apply all the 3 approaches in single application to mixup our form validation logic’s with the validator plug-in supplied predefined validator rules.

Leave a Reply

Your email address will not be published. Required fields are marked *