is string all Numeric by regular expression - Android java.util.regex

Android examples for java.util.regex:Numeric Pattern

Description

is string all Numeric by regular expression

Demo Code

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static boolean isNumeric(String str) {
        boolean isMatches = false;
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if (isNum.matches()) {
            isMatches = true;//from   ww w.ja v a2s.  c o  m
        }
        return isMatches;
    }

}

Related Tutorials