is Number by regex - Java java.util.regex

Java examples for java.util.regex:Match Number

Description

is Number by regex

Demo Code

/**/*from w w  w  . j a  v  a  2  s  .c o m*/
 * Copyright (c)2010-2011 Enterprise Website Content Management System(EWCMS), All rights reserved.
 * EWCMS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * http://www.ewcms.com
 */
//package com.java2s;

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

public class Main {
    public static void main(String[] argv) throws Exception {
        String s = "java2s.com";
        System.out.println(isNumber(s));
    }

    private static Boolean isNumber(String s) {
        Pattern pa = Pattern.compile("[0-9]*");
        Matcher ma = pa.matcher(s);
        if (ma.matches()) {
            return true;
        }
        return false;
    }
}

Related Tutorials