1、java用正则表达式校验MAC地址
- Stringmac="00-E0-20-1C-7C-0C";
- //正则校验MAC合法性
- StringpatternMac="^[A-F0-9]{2}(-[A-F0-9]{2}){5}$";
- if(!Pattern.compile(patternMac).matcher(mac).find()){
- addFieldError("macaddress","MAC地址格式或者大小写错误");
- }
2、java用正则表达式校验MAC地址
Stringip=deviceform.getIpaddress();
/正则校验IP合法性
Patternpattern=Pattern.compile("^((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])$");
if(!pattern.matcher(ip).find()){
addFieldError("ipaddress","IP地址格式不正确");
}
原文链接:https://www.f2er.com/regex/358660.html