Java tutorial
//package com.java2s; import java.util.regex.Pattern; public class Main { public static boolean isCardId(String str) { boolean flag = false; // /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; String check = "(^\\d{18}$)|(^\\d{15}$)|(^\\d{17}(\\d|X|x)$)"; Pattern pattern = Pattern.compile(check); flag = pattern.matcher(str).matches(); return flag; } }