MCPcopy Create free account
hub / github.com/apache/cloudstack / isValidIPv4Cidr

Function isValidIPv4Cidr

ui/src/utils/util.js:106–125  ·  view source on GitHub ↗
(rule, value)

Source from the content-addressed store, hash-verified

104}
105
106export function isValidIPv4Cidr (rule, value) {
107 return new Promise((resolve, reject) => {
108 if (!value) {
109 reject(new Error())
110 return
111 }
112 const cidrRegex = /^(\d{1,3}\.){3}\d{1,3}\/([0-9]|[1-2][0-9]|3[0-2])$/
113 if (!cidrRegex.test(value)) {
114 reject(new Error('Invalid CIDR format'))
115 return
116 }
117 const ip = value.split('/')[0]
118 const octets = ip.split('.').map(Number)
119 if (octets.some(octet => octet < 0 || octet > 255)) {
120 reject(new Error('Invalid CIDR format'))
121 return
122 }
123 resolve()
124 })
125}

Callers

nothing calls this directly

Calls 4

rejectFunction · 0.85
mapMethod · 0.80
resolveFunction · 0.50
testMethod · 0.45

Tested by

no test coverage detected