bool QUIHelper::isIP(const QString &ip)
{
QRegExp RegExp("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)");
return RegExp.exactMatch(ip);
}
bool QUIHelper::isMac(const QString &mac)
{
QRegExp RegExp("^[A-F0-9]{2}(-[A-F0-9]{2}){5}$");
return RegExp.exactMatch(mac);
}
bool QUIHelper::isTel(const QString &tel)
{
if (tel.length() != 11) {
return false;
}
if (!tel.startsWith("13") && !tel.startsWith("14") && !tel.startsWith("15") && !tel.startsWith("18")) {
return false;
}
return true;
}
bool QUIHelper::isEmail(const QString &email)
{
if (!email.contains("@") || !email.contains(".com")) {
return false;
}
return true;
}
int QUIHelper::strHexToDecimal(const QString &strHex)
{
bool ok;
return strHex.toInt(&ok, 16);
}
int QUIHelper::strDecimalToDecimal(const QString &strDecimal)
{
bool ok;
return strDecimal.toInt(&ok, 10);
}
int QUIHelper::strBinToDecimal(const QString &strBin)
{
bool ok;
return strBin.toInt(&ok, 2);
}
QString QUIHelper::strHexToStrBin(const QString &strHex)
{
uchar decimal = strHexToDecimal(strHex);
QString bin = QString::number(decimal, 2);
uchar len = bin.length();
if (len < 8) {
for (int i = 0; i < 8 - len; i++) {
bin = "0" + bin;
}
}
return bin;
}
QString QUIHelper::decimalToStrBin1(int decimal)
{
QString bin = QString::number(decimal, 2);
uchar len = bin.length();
if (len <= 8) {
for (int i = 0; i < 8 - len; i++) {
bin = "0" + bin;
}
}
return bin;
}
QString QUIHelper::decimalToStrBin2(int decimal)
{
QString bin = QString::number(decimal, 2);
uchar len = bin.length();
if (len <= 16) {
for (int i = 0; i < 16 - len; i++) {
bin = "0" + bin;
}
}
return bin;
}
QString QUIHelper::decimalToStrHex(int decimal)
{
QString temp = QString::number(decimal, 16);
if (temp.length() == 1) {
temp = "0" + temp;
}
return temp;
}