package cn.wzt;
public class Reg2 {
public static void main(String[] args) {
String s = "他的手机号是:18236304719";
//判断字符串是否有数字
System.out.println(s.matches(".*\\d.*"));
//判断字符串是否符合电话格式
System.out.println(s.matches("1[3,5,8]\\d{9}"));
//判断字符串是否有手机号
System.out.println(s.matches(".*1[3,5,8]\\d{9}.*"));
//^开头,$结尾
//判断字符串从开头到结尾是不是有一个汉字(字符串只能是一个数字)
System.out.println("中".matches("^[\\u4e00-\\u9fa5]$"));
//判断字符串是否为纯中文
System.out.println("中华人民共和国".matches("^[\\u4e00-\\u9fa5]+$"));
//判断字符串是否全有a-z组成
System.out.println("abc".matches("[a-z]+"));
//判断字符串是否含有a-z字母
System.out.println("1Abc".matches(".*[a-z]+.*"));
}
}
String、正则表达式进行格式化判断,如电话格式等
最新推荐文章于 2024-04-12 12:10:04 发布