views:

170

answers:

2

Hi,

i want to validate textfield which should allow only number 0-9 in any range how can i implement this

Thanks Shakil

A: 

I'm not sure what you mean by "in any range". To do numeric validation you can use the int validator:

     <validator type="int">
          <param name="fieldName">myfield</param>
          <param name="min">0</param>
          <param name="max">9</param>
          <message>MyField needs to be between ${min} and ${max}</message>
      </validator>

I assume you just want integers and not real numbers.

This page describes all the validators that are available.

Vincent Ramdhanie
+1  A: 

Struts2 ships with pretty good documentation. Learn how to use it :)

  1. Start here: http://struts.apache.org/2.1.8.1/docs/guides.html
  2. There's chapter Validation: http://struts.apache.org/2.1.8.1/docs/validation.html
  3. Check section Bundled Validators: http://struts.apache.org/2.1.8.1/docs/validation.html#Validation-BundledValidators
  4. You want to use int validation: http://struts.apache.org/2.1.8.1/docs/int-validator.html
BalusC