check numbers by regex - Java java.util.regex

Java examples for java.util.regex:Match Number

Description

check numbers by regex

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String checkText = "java2s.com";
        System.out.println(checkNum(checkText));
    }/*  w ww.j a  v  a 2 s .co m*/

    /**
     * check numbers
     * 
     * @param checkText
     * @return
     */
    public static boolean checkNum(String checkText) {
        checkText = checkText.trim();
        if (checkText.matches("\\d+")) {
            return true;
        } else {
            return false;
        }
    }
}

Related Tutorials