how about "^\d{1,3}(\.\d{1,2})?$"

Here is the testcase

import org.apache.commons.validator.GenericValidator;

public class TestFloat{


  public static void main(String[] args) throws Exception {

    String[] f = new String[]{"123.23", "123", "1234.23", "1234.234",
"12345.2342", "11234.123.23", "123.3", "1234.23",};

    for(int i=0; i<f.length; i++){
                System.out.println(f[i]+" "+testFloat(f[i]));
        }

  }


  public static boolean testFloat(String f){

          final String PATTERN = "^\\d{1,3}(\\.\\d{1,2})?$";

          return GenericValidator.matchRegexp(f, PATTERN);
  }
}


On Mon, 17 Jan 2005 12:31:37 +0800, Nathan Coast <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I have a price field that I want to validate as a float with these
> additional constraints 1-3 digits before the decimal, if the decimal
> exists, 1-2 digits after the decimal.
> 
> anyone know the regexp that describes this?
> 
> cheers
> Nathan
> --
> Nathan Coast
> Managing Director
> Codeczar Ltd
> mob : (852) 9049 5581
> tel : (852) 2834 8733
> fax : (852) 2834 8755
> web : http://www.codeczar.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to