Java tutorial
//package com.java2s; //License from project: Apache License import android.text.TextUtils; public class Main { private static final int LENGTH_EXPIRY_DATE = 4; public static boolean isValid(String expiry) { if (TextUtils.isEmpty(expiry)) { return false; } if (expiry.length() != LENGTH_EXPIRY_DATE) { return false; } // check all numeric if (!TextUtils.isDigitsOnly(expiry)) { return false; } // check month valid int month = Integer.parseInt(expiry.substring(0, 2)); if (month < 1 || month > 12) { return false; } return true; } }