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

Android examples for java.util.regex:Character Pattern

Description

match Negative 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_NEGATINE_NUMBER = "^-[1-9]\\d*|0$";

    public static boolean NegatineNumber(String value) {
        return match(V_NEGATINE_NUMBER, value);
    }//from w  ww . j av a2  s . c o m

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

Related Tutorials