Add validation function for phone numbers

This commit is contained in:
jrenslin committed 2021-09-25 21:56:01 +02:00
1 parent a6ebab3e03
commit 143a4680e2
1 file changed
+21
+21
View File
@@ -212,6 +212,27 @@ public static function sanitize_email(mixed $input):string {
}
/**
* 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.
*