updated and improved ip address validation

This commit is contained in:
2025-11-12 09:46:59 +00:00
parent 9b996430d0
commit ed271964d8
3 changed files with 29 additions and 15 deletions

View File

@@ -185,15 +185,13 @@ export const reverseZoomMapping = (magnification: string) => {
}
};
export function ValidateIPaddress(ipaddress: string) {
if (!ipaddress) {
return undefined;
} else if (
!/^(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]?)$/.test(
ipaddress
)
) {
return "Invalid IP";
export const ValidateIPaddress = (value: string | undefined) => {
if (!value) return;
const regex =
/^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/;
if (!regex.test(value)) {
return "Invalid IP address format";
}
return undefined;
}
};