/*
A:案例演示
需求:校验邮箱
分析:
*
* 定义邮箱的规则
kangjia@itcast.cn
* 407832217@qq.com
* you_cai@163.com
* pfqy@126.com
*
*
* XinLang@sina.com.cn.xx.google
*
*
* 分析 :
*
* 1.@
* 2.@前面是 所有单词字符 [a-zA-Z_0-9]
* 3.@后面是 单词字符{2,6}
* 4.步骤3后面必须.
* 5.步骤4.的后面再有字母{2,3}
*
*/
public class RegexDemo8 {
public static void main(String[] args) {
//String regex = "[a-zA-Z_0-9]+@[a-zA-Z_0-9]{2,6}(\\.[a-zA-Z_0-9]{2,3}){1,2}";
String regex = "\\w+@\\w{2,6}(\\.\\w{2,3}){1,2}";
String mail1 = "407832217@qq.com";
String mail2 = "kangjia@itcast.cn";
String mail3 = "you_cai@163..com";
String mail4 = "pfqy@126.com";
String mail5 ="XinLang@sina.com.cn";
System.out.println(mail1.matches(regex));
System.out.println(mail2.matches(regex));
System.out.println(mail3.matches(regex));
System.out.println(mail4.matches(regex));
System.out.println(mail5.matches(regex));
}
}
|
|