public static boolean isInteger ( String _str , boolean _allowNegative ) { if ( _str == null ) { return false ; } String regex = "[0-9]+$" ; if ( _allowNegative ) { regex = "^-?" + regex ; } else { regex = "^" + regex ; } return _str . matches ( regex ) ; }
Check if string is an either positive or negative integer .