MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / validateIPorCIDR

Function validateIPorCIDR

frontend/packages/common/src/utils/validate.ts:10–26  ·  view source on GitHub ↗
(rule, value)

Source from the content-addressed store, hash-verified

8}
9
10export const validateIPorCIDR = (rule, value) => {
11 if (!value) {
12 return Promise.resolve()
13 }
14
15 const lines = value.split('\n')
16 const ipCidrRegex =
17 /^(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]?)(\/([0-9]|[1-2][0-9]|3[0-2]))?$/
18
19 for (const line of lines) {
20 if (line && !ipCidrRegex.test(line.trim())) {
21 return Promise.reject($t('输入的IP或CIDR不符合格式'))
22 }
23 }
24
25 return Promise.resolve()
26}
27
28export const validateApiPath = (rule, value) => {
29 if (!value) {

Callers

nothing calls this directly

Calls 1

$tFunction · 0.90

Tested by

no test coverage detected