Re: Ip Address Validation
Quote:
Originally Posted by
bruccutler
...is there a better way to validate the address than capturing the finishedEditing signal and doing it via code (x > 0 && x< 256)?
Also, how do I tell Qt to keep the focus in the current field if the entry is in error? lineEdit.SetFocus() gives me recursion problems with my finishedEditing signal.
A QRegExpValidator might be what you're looking for in both cases here.
Re: Ip Address Validation
No - reg expression will check the values, but won't do a full check for 1-255 for all values. At least not one that I've ever seen.
- Bruce
Re: Ip Address Validation
Quote:
Originally Posted by
bruccutler
No - reg expression will check the values, but won't do a full check for 1-255 for all values.
You could, but it would be a fairly complex regular expression.
Re: Ip Address Validation
So - what is the right way to do this? I think I will set it aside, since I'm sure someone out there has solved this problem with Qt.
- BRC
Re: Ip Address Validation
I think you could do it with the combination of a masked line edit, and a QRegExpValidator that checks for a regex like this: (?:1\d?\d?|2(?:[0-4]\d?|[6789]|5[0-5]?)?|[3-9]\d?|0)(?:\.(?:1\d?\d?|2(?:[0-4]\d?|[6789]|5[0-5]?)?|[3-9]\d?|0)){3}
That said, I haven't tried this myself, so who knows... ;)
Re: Ip Address Validation
Oh my God, what an expression.... How about:
Code:
public:
void fixup
(QString &input
) const {} State validate
(QString &input,
int &pos
) const { if(input.isEmpty()) return Acceptable;
int s = slist.size();
if(s>4) return Invalid;
bool emptyGroup = false;
for(int i=0;i<s;i++){
bool ok;
if(slist[i].isEmpty()){
emptyGroup = true;
continue;
}
int val = slist[i].toInt(&ok);
if(!ok || val<0 || val>255) return Invalid;
}
if(s<4 || emptyGroup) return Intermediate;
return Acceptable;
}
};
Re: Ip Address Validation
This worked perfectly! Thanks so much! It took me a while to get back to it, but this really did the job!
Re: Ip Address Validation
Quote:
Originally Posted by
Jimmy2775
I think you could do it with the combination of a masked line edit, and a QRegExpValidator that checks for a regex like this: (?:1\d?\d?|2(?:[0-4]\d?|[6789]|5[0-5]?)?|[3-9]\d?|0)(?:\.(?:1\d?\d?|2(?:[0-4]\d?|[6789]|5[0-5]?)?|[3-9]\d?|0)){3}
That said, I haven't tried this myself, so who knows... ;)
I know that problem is already solved, but... it's definetely too long regexp. I love the power of regular expressions, so here is my shorter version (w/o non-capturing parentheses, for increased readability), where each octet range from 0 to 255:
^0*(2(5[0-5]|[0-4]\d)|1?\d{1,2})(\.0*(2(5[0-5]|[0-4]\d)|1?\d{1,2})){3}$
QRegExpValidator of course doesn't need ^ and $ assertions.
Re: Ip Address Validation
But how to combine with setMask("000.000.000.000;")?
Re: Ip Address Validation
You can't. But the validator does almost the same job, especially if you implement its fixup method.
Re: Ip Address Validation
Hi I've the same problem...I've to implement a dialog like WinXp TCP/IP Properties of Network Connections->MyConnection Properties:
http://www.windowsnetworking.com/img...s/winrlcl1.gif
How use IP4Validator with that kind of masks (IP Address and Subnet Mask) and how to implemet them?
Re: Ip Address Validation
You can cheat by having four frameless line edits and three labels grouped in a horizontal layout and with overriden key events to move to the next group when the previous one is filled or when arrow keys are used. That's probably what the mentioned dialog does, too.
Re: Ip Address Validation
Quote:
Originally Posted by
wysota
You can cheat by having four frameless line edits and three <a href="http://www.ntsearch.com/search.php?q=labels&v=56">labels</a> grouped in a horizontal layout and with overriden key events to move to the next group when the previous one is filled or when arrow keys are used. That's probably what the mentioned dialog does, too.
Ah ok thanks...that's what I suppose!
And...about reimplementing the fixup function? what's the idea?
Re: Ip Address Validation
That you can change an invalid entry to a valid entry. For instance decimal point in some countries is the dot character and in others it is comma. Thanks to fixup you can detect a comma instead of a dot (or the other way round) and change it to something you consider valid.
Re: Ip Address Validation
Quote:
Originally Posted by
wysota
That you can change an invalid entry to a valid entry. For instance decimal point in some countries is the dot character and in others it is comma. Thanks to fixup you can detect a comma instead of a dot (or the other way round) and change it to something you consider valid.
ah ok thanks...and about fixup to format string like inputmask?
Re: Ip Address Validation
You can do there whatever you like.
Re: Ip Address Validation
can u please write the same code of urs for IP address validation.I cannt understand the code written here .
please help me out .
thanks
Re: Ip Address Validation
how can i use fix up in Ip address validation
Re: Ip Address Validation
You get an invalid address as an argument and you need to change it to a valid one, for example change all values greater than 255 to 255.