正则表达式不会,不会做一道题目,求大神解答,问题如下:

2025-06-21 11:52:39
推荐回答(1个)
回答1:

给你几个验证的方法,验证通过返回true,不通过返回false。

其它输入、输出之类的就不写了

//验证name
Pattern.matches("[a-zA-Z\\d]",name);
//验证age
Pattern.matches("1?[1-9]?\\d?|200",age);
//验证telephone
Pattern.matches("\\d{11}",telphone);
//验证moblePhone
Pattern.matches("\\d{4}\\-\\d{7}",moblePone);
验证email
Pattern.matches("\\w+@\\w+\\.\\w+",email);