DaanHoogland commented on code in PR #11381:
URL: https://github.com/apache/cloudstack/pull/11381#discussion_r2518294667


##########
ui/src/utils/util.js:
##########
@@ -103,6 +103,27 @@ export function toCsv ({ keys = null, data = null, 
columnDelimiter = ',', lineDe
   return result
 }
 
+export function isValidIPv4Cidr (rule, value) {
+  return new Promise((resolve, reject) => {
+    if (!value) {
+      reject(new Error())
+      return
+    }
+    const cidrRegex = /^(\d{1,3}\.){3}\d{1,3}\/([0-9]|[1-2][0-9]|3[0-2])$/
+    if (!cidrRegex.test(value)) {
+      reject(new Error('Invalid CIDR format'))
+      return
+    }
+    const ip = value.split('/')[0]
+    const octets = ip.split('.').map(Number)
+    if (octets.some(octet => octet < 0 || octet > 255)) {
+      reject(new Error('Invalid CIDR format'))
+      return
+    }
+    resolve()
+  })
+}
+
 export function getSingularIfPluralWord(word) {

Review Comment:
   ```suggestion
   export function getSingularIfPluralWord (word) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to