Java - Write code to check if a string is Positive Integer using regular expression

Requirements

Write code to check if a string is Positive Integer using regular expression

Demo

import java.util.regex.Pattern;

public class Main {
  public static void main(String[] argv) {
    String s = "123";
    System.out.println(isPositiveInteger(s));
  }/* ww  w. j a  va2 s .  c  o  m*/

  private static final String POSITIVE_INTEGER_REGEX = "[0-9]+";
  private static final Pattern POSITIVE_INTEGER_PATTERN = Pattern.compile(POSITIVE_INTEGER_REGEX);

  public static final boolean isPositiveInteger(String s) {
    return POSITIVE_INTEGER_PATTERN.matcher(s).matches();
  }
}

Related Exercise