mirror of
https://github.com/nextcloud/server.git
synced 2026-02-15 08:48:14 -05:00
38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
/**
|
|
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
const regexRegex = /^\/(.*)\/([gui]{0,3})$/
|
|
const regexIPv4 = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/(3[0-2]|[1-2][0-9]|[1-9])$/
|
|
const regexIPv6 = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(1([01][0-9]|2[0-8])|[1-9][0-9]|[0-9])$/
|
|
|
|
const validateRegex = function(string) {
|
|
if (!string) {
|
|
return false
|
|
}
|
|
return regexRegex.exec(string) !== null
|
|
}
|
|
|
|
const validateIPv4 = function(string) {
|
|
if (!string) {
|
|
return false
|
|
}
|
|
return regexIPv4.exec(string) !== null
|
|
}
|
|
|
|
const validateIPv6 = function(string) {
|
|
if (!string) {
|
|
return false
|
|
}
|
|
return regexIPv6.exec(string) !== null
|
|
}
|
|
|
|
const stringValidator = (check) => {
|
|
if (check.operator === 'matches' || check.operator === '!matches') {
|
|
return validateRegex(check.value)
|
|
}
|
|
return true
|
|
}
|
|
|
|
export { validateRegex, stringValidator, validateIPv4, validateIPv6 }
|