is String all Numeric by regex - Android java.util.regex

Android examples for java.util.regex:Numeric Pattern

Description

is String all Numeric by regex

Demo Code

import android.text.TextUtils;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }// www.  j a  v  a 2s . c  o  m
        return true;
    }

}

Related Tutorials