is String Float number by regex - Android java.util.regex

Android examples for java.util.regex:Number Pattern

Description

is String Float number by regex

Demo Code


//package com.java2s;

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

public class Main {

    public static boolean isFloat(String str) {
        Pattern pattern = Pattern.compile("^(-?\\d+)(\\.\\d+)?$");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }/*from   w  w w.  j  a  v a 2 s.c  o  m*/
        return true;
    }
}

Related Tutorials