feat(StatusQ.Controls.Validators): introduce `StatusAddressAndEnsValidator`

This commit is contained in:
Pascal Precht 2021-09-10 12:51:16 +02:00 committed by Michał Cieślak
parent f979011323
commit ff549d2822
3 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,15 @@
import StatusQ.Controls 0.1
import StatusQ.Core.Utils 0.1
StatusValidator {
name: "addressOrEns"
errorMessage: "Please enter a valid address or ENS name."
validate: function (t) {
return Utils.isValidAddress(t) || Utils.isValidEns(t) ?
true :
{ actual: t }
}
}

View File

@ -1,6 +1,7 @@
module StatusQ.Controls.Validators module StatusQ.Controls.Validators
StatusAddressValidator 0.1 StatusAddressValidator.qml StatusAddressValidator 0.1 StatusAddressValidator.qml
StatusAddressOrEnsValidator 0.1 StatusAddressValidator.qml
StatusValidator 0.1 StatusValidator.qml StatusValidator 0.1 StatusValidator.qml
StatusMinLengthValidator 0.1 StatusMinLengthValidator.qml StatusMinLengthValidator 0.1 StatusMinLengthValidator.qml
StatusMaxLengthValidator 0.1 StatusMaxLengthValidator.qml StatusMaxLengthValidator 0.1 StatusMaxLengthValidator.qml

View File

@ -18,6 +18,14 @@ QtObject {
return inputValue !== "0x" && /^0x[a-fA-F0-9]{40}$/.test(inputValue) return inputValue !== "0x" && /^0x[a-fA-F0-9]{40}$/.test(inputValue)
} }
function isValidEns(inputValue) {
if (!inputValue) {
return false
}
const isEmail = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/.test(inputValue)
const isDomain = /(?:(?:(?<thld>[\w\-]*)(?:\.))?(?<sld>[\w\-]*))\.(?<tld>[\w\-]*)/.test(inputValue)
return isEmail || isDomain || (inputValue.startsWith("@") && inputValue.length > 1)
}
} }