is string Numeric - Android java.util.regex

Android examples for java.util.regex:Numeric Pattern

Description

is string Numeric

Demo Code

import android.text.Html;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

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

}

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 isMatch(String text, String patternStr) {
        Pattern pattern = Pattern.compile(patternStr);
        Matcher m = pattern.matcher(text);
        if (m.find())
            return true;

        return false;

    }//w w  w.j  av  a  2 s  . c o m

    public static boolean isMatch(String text, String[] patternStrings) {
        for (String patternStr : patternStrings) {
            Pattern pattern = Pattern.compile(patternStr);
            Matcher m = pattern.matcher(text);
            if (m.find())
                return true;
        }
        return false;
    }

}

Related Tutorials