[refactor] Moved isValidIPAddress to its own TS file

This commit is contained in:
Steven Evans
2018-07-04 21:30:50 -04:00
parent 8b98321b9c
commit bdb935d104
5 changed files with 17 additions and 12 deletions
+12
View File
@@ -0,0 +1,12 @@
/**
* Checks whether a IP Address string is valid.
* @param ipaddress A string representing a potential IP Address
*/
export function isValidIPAddress(ipaddress: string) {
const byteRange: string = "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
const regexStr: string = `^${byteRange}\.${byteRange}\.${byteRange}\.${byteRange}$`;
const ipAddressRegex: RegExp = new RegExp(regexStr);
return ipAddressRegex.test(ipaddress);
}