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

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

View File

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

View File

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

View File

@ -14,6 +14,10 @@ QtObject {
}
return returnPos;
}
function isValidAddress(inputValue) {
return inputValue !== "0x" && /^0x[a-fA-F0-9]{40}$/.test(inputValue)
}
}