一、验证是否符合IP地址
#include <regex>
//使用正则表达式
bool equipmentManager::isIP(string ip)
{
regex pattern("((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)");
smatch res;
if(regex_match(ip, res, pattern)){
return true;
}
return false;
}
二、验证是否符合物理地址
bool equipmentManager::isPhysicallocation(string val) {
regex pattern("(^[A-Fa-f\\d]{2}\\.[A-Fa-f\\d]{2}\\.[A-Fa-f\\d]{2}\\.[A-Fa-f\\d]{2}\\.[A-Fa-f\\d]{2}\\.[A-Fa-f\\d]{2}$)");
// let reg = /^[A-Fa-f\d]{2}.[A-Fa-f\d]{2}.[A-Fa-f\d]{2}.[A-Fa-f\d]{2}.[A-Fa-f\d]{2}.[A-Fa-f\d]{2}$/;
smatch res;
if(regex_match(val, res, pattern)){
return true;
}
return false;
}