Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- QValidator::State QNickValidator::validate(const QString &input) const
- {
- if (input.length() > 20)
- {
- return QValidator::Invalid;
- }
- if (input.length() == 0)
- return QValidator::Intermediate;
- if (!isBegEndChar(input[0])) {
- return QValidator::Invalid;
- }
- bool spaced = false;
- bool punct = false;
- for (int i = 0; i < input.length(); i++) {
- if (input[i] == '\n' || input[i] == '%' || input[i] == '*' || input[i] == '<' || input[i] == ':' || input[i] == '(' || input[i] == ')'
- || input[i] == ';')
- return QValidator::Invalid;
- if (input[i].isPunct()) {
- if (punct == true) {
- //Error: two punctuations are not separated by a letter/number
- return QValidator::Invalid;
- }
- punct = true;
- spaced = false;
- } else if (input[i] == ' ') {
- if (spaced == true) {
- //Error: two spaces are following
- return QValidator::Invalid;
- }
- spaced = true;
- } else if (input[i].isLetterOrNumber()) {
- //we allow another punct & space
- punct = false;
- spaced = false;
- }
- if (input[i].category() >= QChar::Other_Control && input[i].category() <= QChar::Other_NotAssigned) {
- return QValidator::Intermediate;
- }
- }
- //let's check if there is at least a letter/number & no whitespace at the end
- if (input.length() == 1 && input[0].isPunct()) {
- return QValidator::Intermediate;
- }
- if (!isBegEndChar(input[input.length()-1])) {
- return QValidator::Intermediate;
- }
- return QValidator::Acceptable;
- }
Add Comment
Please, Sign In to add comment