问题描述
请根据给出的正则表达式来验证邮箱格式是否合法,如果用户输入的格式合法则输出「邮箱格式合法」,否则输出「邮箱格式不合法」。
输入描述:
任意字符串
输出描述:
根据输入的邮箱格式判断其合法于不合法,若输入字符串符合邮箱格式则输出邮箱格式合法,否则输出邮箱格式不合法
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str = scanner.next(); String emailMatcher="[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z0-9]+"; //write your code here...... System.out.println(str.matches(emailMatcher)?"邮箱格式合法":"邮箱格式不合法"); } }
02-14
580
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)