正则表达式联练习,电子邮箱

版权声明:嘻嘻嘻嘻,I see you https://blog.csdn.net/qq_38317309/article/details/85790743
public class TestDemo{
 public static void main(String[] args) throws Exception{
  String str="[email protected]";
  String regex="[a-zA-Z][a-zA-Z\\._\\-0-9]{5,14}@[a-zA-Z\\._\\-0-9]+\\.(com|cn|org|net|cn|com\\.cn)";
  System.out.println(str.matches(regex));
 }
}

用正则表达式验证Email 地址有字母、数字、下划线组成
String str=“”
email 的用户名必须有字母组成,而且可以由字母、数字、- 组成,且长度为6~15位,后缀为.com .cn .net
①m
②ldn8-java.a
③@
④mldn
⑤.
⑥cn
第一个必须是字母
对应的正则式
①[a-zA-Z] 已经占位一个
②[a-zA-Z-
\.0-9]{5~14}
③@
④ [a-zA-Z-\.0-9]
⑤\.
⑥在com、net、cn、org、com.cn
等中选择中任选一个要在一个整体中出现,而且项目之间莺歌是以或的形式出现 (com|cn|net|org)regex="[a-zA-Z][a-zA-Z\.
-0-9]{5,14}@[a-zA-Z\._-0-9]+\.(com|cn|org|net\.cn|net\.cn)"

猜你喜欢

转载自blog.csdn.net/qq_38317309/article/details/85790743