 <p>You can use Qt's <a href="http://qt-project.org/doc/qt-4.8/qlineedit.html#setValidator" rel="nofollow">Input Validator</a> feature to achieve this goal.</p> <p>The following snippet will restrict the input on a line edit as you specified.</p> <pre><code>QRegExp re("^[[,(]{1,1}(0|[1-9]{1,1}[0-9]{0,9})[,]{1,1}(0|[1-9]{1,1}[0-9]{0,9})[],)]{1,1}$"); QRegExpValidator *validator = new QRegExpValidator(re, this); ui-&gt;lineEdit-&gt;setValidator(validator); </code></pre> <p><strong>Edit</strong> Updated the regex</p>