more flexible SetMaskInput



  • Hello,
    I would like to make a mask input in a line edit for an IP address. Most often I find the suggestion
    mylineEdit->setInputMask("000.000.000.000");
    But if I enter an IP address like 192.168.0.100 it would look like 192.168.0 .100 with two spaces in it.
    Is there a way to avoid that?
    I would appreciate any help! Thank you


  • Moderators

    @NinaWeber
    use QRegExpValidator (Qt4) or QRegularExpressionValidator (Qt5)
    with the following regexp:

    "25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
    

    or less accurate:

    "(?:[0-9]{1,3}\.){3}[0-9]{1,3}"
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.