以下是常用的一些正则总结
邮箱
String regex = "^([\\w-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
IP地址
String regex = "/^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/";
URL
String regex = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
电话号码
String regex = "^(\\d{3,4}-)?\\d{6,8}$";
邮政编码
String regex = "^\\d{6}$";
身份证号码
18位
String regex = "^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$";
15位
String regex = "^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$";
汉字
String regex = "^[\u4e00-\u9fa5],{0,}$";
密码(8-16 英+数字)
英文&&数字
String regex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$";
以上是常用的一些正则总结
正则验证小工具
链接:https://pan.baidu.com/s/1KkH7hi0pZ2zDYnj5KKdZIA
提取码:2tej
OK that‘s all.
原文:https://www.cnblogs.com/zuichao/p/12484498.html