How can the regular expression pattern be modified to allow for both formatted and unformatted phone number inputs?

To allow for both formatted and unformatted phone number inputs in a regular expression pattern, we can modify the pattern to accept different variations of phone number formats. This can be done by using optional characters and groups in the pattern to match different formats such as (123) 456-7890 and 1234567890. By making certain parts of the pattern optional, we can match a wider range of phone number inputs.

$pattern = '/^\(?\d{3}\)?[\s-]?\d{3}[\s-]?\d{4}$/';
$phone_number = "(123) 456-7890";

if (preg_match($pattern, $phone_number)) {
    echo "Valid phone number format";
} else {
    echo "Invalid phone number format";
}