What potential pitfalls should be considered when validating phone numbers using regular expressions in PHP?
One potential pitfall when validating phone numbers using regular expressions in PHP is not accounting for international phone number formats. To solve this, you can modify the regular expression pattern to allow for different country codes and phone number formats.
// Validate phone number with international format
$phone_number = '+1-555-123-4567';
if (preg_match('/^\+\d{1,3}-\d{3}-\d{3}-\d{4}$/', $phone_number)) {
echo 'Valid phone number';
} else {
echo 'Invalid phone number';
}