第十三次作业
一、题目:题目:定义判断电子邮箱的正则表达式,判断输入的字符串是否为电子邮箱地址。
二、代码:
1 import java.util.*; 2 public class erishiyirilianxi { 3 4 5 public static void main(String[] args) { 6 7 System.out.println("请输入邮箱地址,如:qwers@123.com"); 8 Scanner in=new Scanner(System.in); 9 String s1=in.nextLine(); 10 String regex="\\w+{5}[@]\\w{3}+[.]\\w+{3}"; 11 if(s1.matches(regex)){ 12 System.out.println("用户名正确"); 13 } 14 else{ 15 System.out.println("错误!请按规定长度输入"); 16 17 18 } 19 20 } 21 }
三、运行结果: