PowerShell can use regular expressions to validate user input. All you need is a regular expression that adequately defines the pattern you are seeking. Fortunately, you do not need to create regular expressions from scratch. Simply Google them and then replace the pattern string in the example below to validate other user input:
$ip = Read-Host "Enter IP"
} while ($ip -notmatch $pattern)