problem with zero value validation using format mask (regexp)

Discussions

General J2EE: problem with zero value validation using format mask (regexp)

  1. I have to restrict zero numeric value and non-numeric values using format mask. I have done the following example. It is restricting Non-Numeric and "0" values. But, it is not restricting "00" and "000" values. Code: - ==== Pattern pat = Pattern.compile("[1-9]|([0-9]{2,3})"); Matcher matcher = pat.matcher("00"); boolean flag = matcher.matches(); System.out.println(flag);
  2. I have to restrict zero numeric value and non-numeric values using format mask.
    I have done the following example.
    It is restricting Non-Numeric and "0" values.
    But, it is not restricting "00" and "000" values.


    Code: -
    ====

    Pattern pat = Pattern.compile("[1-9]|([0-9]{2,3})");
    Matcher matcher = pat.matcher("00");
    boolean flag = matcher.matches();
    System.out.println(flag);
    I am not sure if I understand your question but your regular expression looks like it is accepting 00 or 000 to me and if this is the case, the following is what I think you may look for: Pattern pat = Pattern.compile("[1-9]|([1-9]{2,3})"); Matcher matcher = pat.matcher("00"); boolean flag = matcher.matches(); System.out.println(flag);