首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

求生日的正则表达式,非百度搜的,解决思路

2012-02-01 
求生日的正则表达式,非百度搜的,急谢谢,明天要交的作业import java.io.BufferedReaderimport java.io.IOE

求生日的正则表达式,非百度搜的,急
谢谢,明天要交的作业


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class yuangong {
String name, sex, birthday, telephone, email, enducation;
int pay;
BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));

public yuangong(String aname, String asex, String abirthday,
String atelephone, String aemail, String aenducation, int apay) {
name = aname;
sex = asex;
birthday = abirthday;
telephone = atelephone;
email = aemail;
enducation = aenducation;
pay = apay;
}

public void nameInput() {// 姓名的输入
try {
String N=new String();
boolean b=true;
while(b){
N = bin.readLine();
if(!isNameNumericRegex(N)){
System.out.println("格式错误!");
continue;
}
else{
b=false;

}
}
}catch (IOException e) {
e.printStackTrace();

}
}

void sexTnput() {// 性别的输入
try {
String s=new String();
boolean b=true;
while(b){
s = bin.readLine();
if(!isSexNumericRegex(s)){
System.out.println("格式错误!请输入男或女");
continue;
}
else{
b=false;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}

void birthdayInput() {// 生日的输入
try {
String bir=new String();
boolean b=true;
while(b){
bir=bin.readLine();
if(!BirthdayNumberiRecgex(bir)){
System.out.println("格式错误!");
continue;
}
else{

b=false;
}
}
} catch (IOException e1) {
e1.printStackTrace();
}
}

/*private boolean BirthdayNumberiRecgex(String bir) {
// TODO Auto-generated method stub
return false;
}

private boolean BirthdayNumberiRecgex(String bier) {
// TODO Auto-generated method stub
return false;
}
*/
void telephoneInput() {// 电话的输入
try {
Integer tel=new Integer(pay);
boolean b=true;
while(b){
tel = Integer.parseInt(bin.readLine());
if(!isTelNumericRegex(tel)){
System.out.println("格式输入错误!请重新输入");
}
else{
b=false;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}

void emailInput() {// 邮箱的输入
try {
String e=new String();
boolean b=true;
while(b){
if(!isEmailNumericRegex(e)){
System.out.println("格式错误!请重新输入");
continue;
}
else{
email = bin.readLine();
b=false;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}

void enducationInput() {// 学历的输入
try {
String endu=new String();
boolean b=true;
while(b){
if(!isEduNumericRegex(endu)){
System.out.println("格式错误!请重新输入");
continue;
}
else{
enducation = bin.readLine();
b=false; 
}
}
} catch (IOException e) {
e.printStackTrace();
}
}

private boolean isEduNumericRegex(String endu) {
// TODO Auto-generated method stub
return false;
}

void payInput() {//工资的输入
try {
Integer pay=new Integer(0);
boolean b=true;
while(b){
pay = Integer.parseInt(bin.readLine());
if(!isPayNumericRegex(pay)){
System.out.println("格式错误!请重新输入");
continue;
}
else{
b=false;
}

}catch (IOException e) {
e.printStackTrace();


}
}
private boolean isPayNumericRegex(Integer pay2) {
// TODO Auto-generated method stub
return false;
}

public String toString(){
return getClass().getName()+"姓名:"+name+",性别:"+sex+",生日"+birthday+
",电话:"+telephone+",邮箱:"+email+"学历:"+enducation;
}

public static final boolean isNameNumericRegex(String str) {
Pattern name = Pattern.compile("^[a-z]+$");//姓名的正则表达式
//Pattern name = Pattern.compile("^[a-zA-Z]{1}[a-zA-Z|-|_]{2,16}[a-zA-Z0-9]{1}$");//姓名的正则表达式
Matcher matchern = name.matcher(str.trim());
return matchern.matches();

public static final boolean isSexNumericRegex(String str){
Pattern sex=Pattern.compile("^[w]|[m]$"); //性别的正则表达式
Matcher matcherS=sex.matcher(str.trim());
return matcherS.matches();
}
/*public static final boolean isDateNumericRegex(String str){
Pattern birthday=Pattern.compile("^\\d{4}-\\d{2}-\\d{2}$");//生日的正则表达式
Matcher matcherB=birthday.matcher(str.trim());
return matcherB.matches();
}*/
public static final boolean isTelNumericRegex(Integer tel){
Pattern telephone=Pattern.compile("^1\\d{10}$");//电话的正则表达式
Matcher matcherT=telephone.matcher(tel.toString());
return matcherT.matches();
}
public static final boolean isEmailNumericRegex(String str){
Pattern email=Pattern.compile("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$");//邮箱的正则表达式
Matcher matcherE=email.matcher(str.trim());
return matcherE.matches();
}
public static final boolean isNumericRegex(String str){
Pattern enducation=Pattern.compile("[高中]|[本科]|[硕士]]");//学历的正则表达式
Matcher matcherED=enducation.matcher(str.trim());
return matcherED.matches();
}

public static void main(String args[]) {
yuangong yg = new yuangong("", "", "", "", "", "", 0);
System.out.println("请输入姓名:");
yg.nameInput();
//System.out.println("yg.name="+yg.name);
System.out.println("请输入性别:");
yg.sexTnput();
System.out.println("请输入出生年月:");
yg.birthdayInput();
System.out.println("请输入手机号:");
yg.telephoneInput();
System.out.println("请输入邮箱:");
yg.emailInput();
System.out.println("请输入学历:");
yg.enducationInput();
System.out.println("该员工信息为:"+yg);

}

}
不知道这个生日的表达式是什么样的,老是出错。谢谢

[解决办法]
我很难想象你能够看懂!

(?:[0-9]{1,4}(?<!^0?0?0?0))-(?:0?[1-9]|1[0-2])-(?:0?[1-9]|1[0-9]|2[0-8]|(?:(?<=-(?:0?[13578]|1[02])-)(?:29|3[01]))|(?:(?<=-(?:0?[469]|11)-)(?:29|30))|(?:(?<=(?:(?:[0-9]{0,2}(?!0?0)(?:[02468]?(?<![13579])[048]|[13579][26]))|(?:(?:[02468]?[048]|[13579][26])00))-0?2-)(?:29)))

验证日期的Java正则表达式
http://blog.csdn.net/bao110908/article/details/2132973

热点排行