How do I verify the following strings?

The

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");
}

is not empty / ^ [., /:] + $/
can be empty / ^ [., /:] * $/
are you asking the wrong question? A string contains only'., /: 'what's the meaning of checking


regular
^ [., /:] + $


/ ^ (\. |\, |\ / |\: | [A-Za-z0-9] |\ s) + $/ like this?

Menu