is Integer by regex - Java java.util.regex

Java examples for java.util.regex:Match Number

Description

is Integer by regex

Demo Code


//package com.java2s;
import java.util.regex.*;

public class Main {
    public static void main(String[] argv) throws Exception {
        String str = "java2s.com";
        System.out.println(isInteger(str));
    }//  ww  w  . j  a  v a2  s . co m

    public static boolean isInteger(String str) {
        Pattern pattern = Pattern.compile("^[\\d]*$");
        return pattern.matcher(str).matches();
    }
}

Related Tutorials