void EmailDialog::toAddressChanged() { QString to, bcc, cc; to = toAddress->text().trimmed(); bcc = bccAddress->text().trimmed(); cc = ccAddress->text().trimmed(); // Setup regular expression to test email addresses QRegExp mailREX("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b"); mailREX.setCaseSensitivity(Qt::CaseInsensitive); mailREX.setPatternSyntax(QRegExp::RegExp); // Check if "to" address is valid bool validTo = true; QStringList toList = tokenizeString(to); for (int i=0; i<toList.size(); i++) { if (!mailREX.exactMatch(toList[i])) validTo = false; } // check if "cc" address is valid bool validCc = true; QStringList ccList = tokenizeString(cc); for (int i=0; i<ccList.size(); i++) { if (!mailREX.exactMatch(ccList[i])) validCc = false; } // Check if "bcc" address is valid bool validBcc = true; QStringList bccList = tokenizeString(bcc); for (int i=0; i<bccList.size(); i++) { if (!mailREX.exactMatch(bccList[i])) validBcc = false; } // If we have all vaild email addresses or ccSelf is checked, then // we can send an email. if ((validTo && validCc && validBcc) || ccSelf->isChecked()) sendButton->setEnabled(true); else sendButton->setEnabled(false); // If no emails are specified and we are not going to cc oursel, // then we can't send. if (to == "" && cc == "" && bcc == "" && !ccSelf->isChecked()) sendButton->setEnabled(false); }
bool GUI::Registration::checkField() { QRegExp mailREX("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b"); mailREX.setCaseSensitivity(Qt::CaseInsensitive); mailREX.setPatternSyntax(QRegExp::RegExp); if (!mailREX.exactMatch(ui->emailEdit->text())) { ui->warningText->setStyleSheet("color : red; font: 9pt \"MS Shell Dlg 2\";font-weight: bold;"); ui->warningText->setText("Invalid email."); return false; } if (ui->usernameEdit->text().toStdString().empty() || ui->usernameEdit->text().toStdString() == "Username") { ui->warningText->setStyleSheet("color : red; font: 9pt \"MS Shell Dlg 2\";font-weight: bold;"); ui->warningText->setText("Username cannot be blank."); return false; } if (ui->emailEdit->text().toStdString().empty() || ui->emailEdit->text().toStdString() == "Email") { ui->warningText->setStyleSheet("color : red; font: 9pt \"MS Shell Dlg 2\";font-weight: bold;"); ui->warningText->setText("Email cannot be blank."); return false; } if (ui->firstnameEdit->text().toStdString().empty() || ui->firstnameEdit->text().toStdString() == "Firstname"){ ui->warningText->setStyleSheet("color : red; font: 9pt \"MS Shell Dlg 2\";font-weight: bold;"); ui->warningText->setText("Firstname cannot be blank."); return false; } if (ui->lastnameEdit->text().toStdString().empty() || ui->lastnameEdit->text().toStdString() == "Lastname"){ ui->warningText->setStyleSheet("color : red; font: 9pt \"MS Shell Dlg 2\";font-weight: bold;"); ui->warningText->setText("Lastname cannot be blank."); return false; } if (ui->passwordConfirmationEdit->text().toStdString().empty() || ui->passwordEdit->text().toStdString().empty()) { ui->warningText->setStyleSheet("color : red; font: 9pt \"MS Shell Dlg 2\";font-weight: bold;"); ui->warningText->setText("Password cannot be blank."); return false; } if (ui->passwordConfirmationEdit->text().toStdString() != ui->passwordEdit->text().toStdString()) { ui->warningText->setStyleSheet("color : red; font: 9pt \"MS Shell Dlg 2\";font-weight: bold;"); ui->warningText->setText("Password does not match."); return false; } return true; }