fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.regex.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String[] numbers = {"", "12345", "00000", "100000", "000001", "010"};
  14.  
  15. for (String n : numbers) {
  16. System.out.printf("Number '%s' -> valid %s\n", n, employeeNumberCheck(n));
  17. }
  18. }
  19.  
  20. private static final Pattern validEmployeeNumber = Pattern.compile("^[0-9]*[1-9][0-9]*$");
  21.  
  22. private static boolean employeeNumberCheck(String employeeNumber){
  23. return validEmployeeNumber.matcher(employeeNumber).matches();
  24. }
  25.  
  26. }
Success #stdin #stdout 0.12s 321600KB
stdin
Standard input is empty
stdout
Number '' -> valid false
Number '12345' -> valid true
Number '00000' -> valid false
Number '100000' -> valid true
Number '000001' -> valid true
Number '010' -> valid true