Merge pull request #23967 from woocommerce/fix/23947
Fix phone number format to accept "(", and ")"
This commit is contained in:
commit
09408d9296
|
@ -976,7 +976,7 @@ function wc_format_phone_number( $phone ) {
|
||||||
if ( ! WC_Validation::is_phone( $phone ) ) {
|
if ( ! WC_Validation::is_phone( $phone ) ) {
|
||||||
return '';
|
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 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -792,6 +792,7 @@ class WC_Tests_Formatting_Functions extends WC_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_wc_format_phone_number() {
|
public function test_wc_format_phone_number() {
|
||||||
$this->assertEquals( '1-610-385-0000', wc_format_phone_number( '1.610.385.0000' ) );
|
$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 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( '', wc_format_phone_number( '+47 0000 00003' ) );
|
||||||
$this->assertEquals( '27 00 00 0000', wc_format_phone_number( '27 00 00 0000' ) );
|
$this->assertEquals( '27 00 00 0000', wc_format_phone_number( '27 00 00 0000' ) );
|
||||||
|
|
Loading…
Reference in New Issue