Add validation function for phone numbers

This commit is contained in:
Joshua Ramon Enslin 2021-09-25 21:56:01 +02:00
parent a6ebab3e03
commit 143a4680e2
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -212,6 +212,27 @@ final class MD_STD_IN {
}
/**
* Sanitizes and validates a phone number. An empty string passes.
*
* @param mixed $input Input string.
*
* @return string
*/
public static function validate_phone_number(mixed $input):string {
if ($input === "") {
return "";
}
if (!preg_match("#^[()0-9/ +-]+$#", $input)) {
throw new MDgenericInvalidInputsException("Invalid phone number entered.");
}
return $input;
}
/**
* Sanitizes a string to a float.
*