match Positive Number by regex - Android java.util.regex

Android examples for java.util.regex:Numeric Pattern

Description

match Positive Number by regex

Demo Code


//package com.java2s;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    private static final String V_POSITIVE_NUMBER = "^[1-9]\\d*|0$";

    public static boolean PositiveNumber(String value) {
        return match(V_POSITIVE_NUMBER, value);
    }/*  w  w w  .j a  v  a  2s . co  m*/

    private static boolean match(String regex, String str) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        return matcher.matches();
    }
}

Related Tutorials