string can only be swapped for . , /:
, cannot contain other characters, you only need to verify whether the string contains only the above four characters.
$string = "10.0.3.1, 10.0.0.0/16,2001:db8:100:934b::3:1, 2001:db8:100:934b::/64";
if (checkString($string)) {
return true;
} else {
return false;
}
function checkString(string $string) {
//
}
//
if (preg_match("/^(\.|\,|\/|\:)+$/", $string)) {
var_dump("yes");
} else {
var_dump("no");//no
}
//
if (preg_match("/^[a-zA-Z0-9.\/:, ]+$/", $string)) {
var_dump("yes");
} else {
var_dump("no");
}