Java Regex Int Validate parseInt(String value)

Here you can find the source of parseInt(String value)

Description

parse Int

License

GNU General Public License

Declaration

public static Integer parseInt(String value) 

Method Source Code

//package com.java2s;
/*/*from www  . ja  v a2 s  .co  m*/
 * This is the source code of Telegram for Android v. 2.x.x.
 * It is licensed under GNU GPL v. 2 or later.
 * You should have received a copy of the license in this archive (see LICENSE).
 *
 * Copyright Nikolai Kudashov, 2013-2015.
 */

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

public class Main {
    public static Pattern pattern = Pattern.compile("[0-9]+");

    public static Integer parseInt(String value) {
        if (value == null) {
            return 0;
        }
        Integer val = 0;
        try {
            Matcher matcher = pattern.matcher(value);
            if (matcher.find()) {
                String num = matcher.group(0);
                val = Integer.parseInt(num);
            }
        } catch (Exception e) {
            //FileLog.e("tmessages", e);
        }
        return val;
    }
}

Related

  1. parseInt(Object str)
  2. parseInt(String[] strs)
  3. parseInteger(String attrVal)
  4. parseInteger(String inStr, Integer def)
  5. parseInteger(String key, String sourceString)