updated and improved ip address validation
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user