status-desktop/ui/imports/shared/validators/DisplayNameValidators.qml

61 lines
2.3 KiB
QML
Raw Normal View History

import QtQuick 2.15
import StatusQ.Controls.Validators 0.1
import AppLayouts.Communities.stores 1.0
import utils 1.0
QtObject {
id: root
/**
* communitiesStore and myDisplayName are optional. When provided
*/
property CommunitiesStore communitiesStore
property string myDisplayName
readonly property list<StatusValidator> validators: [
StatusValidator {
name: "startsWithSpaceValidator"
validate: t => !(t.startsWith(" ") || t.endsWith(" "))
errorMessage: qsTr("Display Names cant start or end with a space")
},
StatusRegularExpressionValidator {
regularExpression: /^$|^[a-zA-Z0-9\-_\u0020]+$/
errorMessage: qsTr("Invalid characters (use A-Z and 0-9, hyphens and underscores only)")
},
StatusMinLengthValidator {
minLength: Constants.keypair.nameLengthMin
errorMessage: qsTr("Display Names must be at least %n character(s) long",
"", Constants.keypair.nameLengthMin)
},
// TODO: Create `StatusMaxLengthValidator` in StatusQ
StatusValidator {
name: "maxLengthValidator"
validate: t => t.length <= Constants.keypair.nameLengthMax
errorMessage: qsTr("Display Names cant be longer than %n character(s)",
"", Constants.keypair.nameLengthMax)
},
StatusValidator {
name: "endsWith-ethValidator"
validate: t => !(t.endsWith("-eth") || t.endsWith("_eth") || t.endsWith(".eth"))
errorMessage: qsTr("Display Names cant end in “.eth”, “_eth” or “-eth”")
},
StatusValidator {
name: "isAliasValidator"
validate: function (t) { return !Utils.isAlias(t) }
errorMessage: qsTr("Adjective-animal Display Name formats are not allowed")
},
StatusValidator {
name: "isDuplicateInComunitiesValidator"
validate: displayName => {
if (!root.communitiesStore || displayName === root.myDisplayName)
return true
return !communitiesStore.isDisplayNameDupeOfCommunityMember(displayName)
}
errorMessage: qsTr("This Display Name is already in use in one of your joined communities")
}
]
}