Search code examples
regexqtqregularexpression

QRegularExpression Lineedit Validatoin


Hello i'm trying to validate the data (consisting of names of 2 or more words) from a lineedit widget using regular expressions in qt the issue is that qt is allowing anything in the lineedit widget my code is below, thank you.

QRegularExpression Company_Name("/([A-Z|a-z|0-9])/g");
QRegularExpressionMatch Company_Name_Match = Company_Name.match(ui->lineEdit_Company_Name->text())
if(Company_Name_Match.hasMatch())
{
    ErrorLog = ErrorLog + "Company Name contains charagters that are not alphanumeric\n";
    ui->lineEdit_Company_Name->setStyleSheet("border: 1px solid red");

Thank you


Solution

  • i'm trying to validate the data (consisting of names of 2 or more words)

    ^[a-zA-Z0-9]+(\s[a-zA-Z0-9]+)+$