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

This commit is contained in:
Pascal Precht 2021-11-02 11:26:24 +01:00 committed by r4bbit.eth
parent dee9f43761
commit a91558655c
3 changed files with 20 additions and 0 deletions

View File

@ -0,0 +1,15 @@
import StatusQ.Core.Utils 0.1
import StatusQ.Controls 0.1
StatusValidator {
name: "url"
errorMessage: "Please enter a valid URL"
validate: function (value) {
return Utils.isURL(value);
}
}

View File

@ -6,4 +6,5 @@ StatusAsyncValidator 0.1 StatusAsyncValidator.qml
StatusAsyncEnsValidator 0.1 StatusAsyncEnsValidator.qml
StatusMinLengthValidator 0.1 StatusMinLengthValidator.qml
StatusMaxLengthValidator 0.1 StatusMaxLengthValidator.qml
StatusUrlValidator 0.1 StatusUrlValidator.qml
StatusValidator 0.1 StatusValidator.qml

View File

@ -27,6 +27,10 @@ QtObject {
return isEmail || isDomain || (inputValue.startsWith("@") && inputValue.length > 1)
}
function isURL(text) {
return (/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}(\.[a-zA-Z0-9()]{1,6})?\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/.test(text))
}
function uuid() {
return Date.now().toString(36) + Math.random().toString(36).substr(2, 5)
}