Add validation function for phone numbers
This commit is contained in:
parent
a6ebab3e03
commit
143a4680e2
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user