Merge pull request #23967 from woocommerce/fix/23947

Fix phone number format to accept "(", and ")"
This commit is contained in:
Claudio Sanches 2019-06-24 12:09:09 -03:00 committed by GitHub
commit 09408d9296
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View File

@ -976,7 +976,7 @@ function wc_format_phone_number( $phone ) {
if ( ! WC_Validation::is_phone( $phone ) ) {
return '';
}
return preg_replace( '/[^0-9\+\-\s]/', '-', preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $phone ) );
return preg_replace( '/[^0-9\+\-\(\)\s]/', '-', preg_replace( '/[\x00-\x1F\x7F-\xFF]/', '', $phone ) );
}
/**

View File

@ -792,6 +792,7 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
*/
public function test_wc_format_phone_number() {
$this->assertEquals( '1-610-385-0000', wc_format_phone_number( '1.610.385.0000' ) );
$this->assertEquals( '(32) 3212-2345', wc_format_phone_number( '(32) 3212-2345' ) );
// This number contains non-visible unicode chars at the beginning and end of string, which makes it invalid phone number.
$this->assertEquals( '', wc_format_phone_number( '+47 0000 00003' ) );
$this->assertEquals( '27 00 00 0000', wc_format_phone_number( '27 00 00 0000' ) );