Here a solution:
// match the Bytes can be from 0-199 or 200-249 or 250-255 but not a number with one 0 at the beginning like 001 or 020
QString Byte
= "(?!0[0-9])(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
rxip.setPattern("^" + Byte + "\\." + Byte + "\\." + Byte + "\\." +
Byte + "$");
rxnetmask.setPattern("^255\\.255\\.255\\.(?:255|254|252|248|240|224|192|128|0)$|^255\\.255\\.(?:254|252|248|240|224|192|128|0)\\.0$|^255\\.(?:254|252|248|240|224|192|128|0)\\.0\\.0$|^(?:254|252|248|240|224|192|128|0)\\.0\\.0\\.0$");
ip->setValidator(ValIPAddr);
mask->setValidator(ValNetMask);
QRegExpValidator* ValIPAddr;
QRegExpValidator* ValNetMask;
// match the Bytes can be from 0-199 or 200-249 or 250-255 but not a number with one 0 at the beginning like 001 or 020
QString Byte = "(?!0[0-9])(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
QRegExp rxip;
rxip.setPattern("^" + Byte + "\\." + Byte + "\\." + Byte + "\\." +
Byte + "$");
ValIPAddr = new QRegExpValidator(rxip, 0);
QRegExp rxnetmask;
rxnetmask.setPattern("^255\\.255\\.255\\.(?:255|254|252|248|240|224|192|128|0)$|^255\\.255\\.(?:254|252|248|240|224|192|128|0)\\.0$|^255\\.(?:254|252|248|240|224|192|128|0)\\.0\\.0$|^(?:254|252|248|240|224|192|128|0)\\.0\\.0\\.0$");
ValNetMask = new QRegExpValidator(rxnetmask, 0);
ip->setValidator(ValIPAddr);
mask->setValidator(ValNetMask);
To copy to clipboard, switch view to plain text mode
Bookmarks