is Id Card Number by regular expression - Android java.util.regex

Android examples for java.util.regex:Number Pattern

Description

is Id Card Number by regular expression

Demo Code

import android.annotation.SuppressLint;
import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    /**/*  w w  w.j  a  va2 s  . co m*/
     * verify id card number
     * 
     * @param str
     * @return
     */
    public static boolean isIdCardNumber(String str) {
        Pattern p = Pattern
                .compile("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{4}$");
        Matcher m = p.matcher(str);
        return m.matches();
    }

}

Related Tutorials