Tag:web text algorithm ret port fda parse ext validation
Import Java.text.simpledateformat;import java.util.date;import java.util.hashmap;import java.util.Map;/** * ID information algorithm class * * @author Javaweb * */public class Cardutil {/** * According to the ID number of the current identity card holder's gender and age 18 ID Card * * @return * @throws Exception * * public static map<string, object> Getcarinfo (String cardcode) throws Exception {map<string, object> Map = new H Ashmap<string, object> (); String year = cardcode.substring (6). substring (0, 4);//gets years string Yue = cardcode.substring (Ten). substring (0, 2);//Get month// String day=cardcode.substring (n). substring (0,2);//Get Day string sex;if (Integer.parseint (cardcode.substring (16). SUBSTRING (0, 1))% 2 = = 0) {//judge sex sex = "female";} else {sex = "male";} Date date = new Date (),//Gets the current system time SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd"); String fyear = Format.format (date). substring (0, 4);//Current year string Fyue = Format.format (date). substring (5, 7);//month//Strin G Fday=format.format (date). substring (8,10); int age = 0;if (Integer.parseint (Yue) <= INTEGER.PARseint (Fyue)) {//the month in which the current month is greater than the user's origin indicates that the age = Integer.parseint (fyear)-integer.parseint (year) + 1;} else {//the current user has not yet been born age = I Nteger.parseint (Fyear)-integer.parseint (year);} Map.put ("Sex", sex); Map.put ("Age", age); return map; /** * 15-digit ID Verification * * @param * @throws Exception */public static map<string, object> getcarinfo15w (String card) throws Exception {map<string, object> Map = new hashmap<string, object> (); String uyear = "+" + card.substring (6, 8);//year string Uyue = Card.substring (8, 10);//month//String uday=card.substring (10, 12);//day String usex = card.substring (14, 15);//user's gender string sex;if (Integer.parseint (usex)% 2 = = 0) {sex = "female";} else {SE x = "Male";} Date date = new Date (),//Gets the current system time SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd"); String fyear = Format.format (date). substring (0, 4);//Current year string Fyue = Format.format (date). substring (5, 7);//month//Strin G Fday=format.format (date). substring (8,10); int age = 0;if (Integer.parseint (Uyue) <= Integer.parseint (Fyue) {//the month in which the current month is greater than the user's origin indicates that the age = Integer.parseint (fyear)-Integer.parseint (uyear) + 1;} else {//the current user has not yet been born age = Integer . parseint (Fyear)-Integer.parseint (uyear); Map.put ("Sex", sex); Map.put ("Age", age); return map;}}
Java based on the ID number and the tool class that gets the user's age and gender