is a string a Number by regex - Android java.util.regex

Android examples for java.util.regex:Number Pattern

Description

is a string a Number by regex

Demo Code

import android.content.Context;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static Boolean isNumber(String str) {
        Boolean isNumber = false;
        String expr = "^[0-9]+$";
        if (str.matches(expr)) {
            isNumber = true;//w  w  w . j  ava 2s .com
        }
        return isNumber;
    }

}

Related Tutorials