From 8cf7ee9c71a57a92b35af8bb69c44d4f3030203e Mon Sep 17 00:00:00 2001 From: Ian G Date: Tue, 16 Apr 2024 15:59:28 +0900 Subject: [PATCH] Japanese phone number support --- lib/src/phone_number.dart | 44 ++++++++++++++++++++++++++++++ test/specs/phone_number.dart | 52 ++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/lib/src/phone_number.dart b/lib/src/phone_number.dart index a8be12e..5871a72 100644 --- a/lib/src/phone_number.dart +++ b/lib/src/phone_number.dart @@ -79,6 +79,48 @@ class PhoneNumber { '0049 (0)### ######x##', '0049 (0)### ######/##', ]; + static const jaPhoneNumberPatterns = [ + // // Standard non-geographic 10-digit phone number formats + '0#########', + '0#-####-####', + '(0#) ####-####', + '0##-###-####', + '(0##) ###-####', + '0###-##-####', + '(0###) ##-####', + // // Standard non-geographic 11-digit phone number formats + '0##########', + '0#-#####-####', + '(0#) #####-####', + '0##-####-####', + '(0##) ####-####', + '0###-###-####', + '(0###) ###-####', + // // Standard non-geographic 10-digit phone number formats with country code + '+810#########', + '+81-0#########', + '+81 0#########', + '+81-0#-####-####', + '+81 0#-####-####', + '+81 (0#) ####-####', + '+81-0##-###-####', + '+81 0##-###-####', + '+81 (0##) ###-####', + '+81-0###-##-####', + '+81 0###-##-####', + '+81 (0###) ##-####', + // // Standard non-geographic 11-digit phone number formats with country code + '+810##########', + '+81-0#-#####-####', + '+81 0#-#####-####', + '+81 (0#) #####-####', + '+81-0##-####-####', + '+81 0##-####-####', + '+81 (0##) ####-####', + '+81-0###-###-####', + '+81 0###-###-####', + '+81 (0###) ###-####', + ]; const PhoneNumber(this.random); @@ -87,4 +129,6 @@ class PhoneNumber { String us() => random.fromPattern(usPhoneNumberPatterns); String de() => random.fromPattern(dePhoneNumberPatterns); + + String ja() => random.fromPattern(jaPhoneNumberPatterns); } diff --git a/test/specs/phone_number.dart b/test/specs/phone_number.dart index e906174..f175bba 100644 --- a/test/specs/phone_number.dart +++ b/test/specs/phone_number.dart @@ -129,4 +129,56 @@ void main() { } }); }); + group('ja', () { + test('should be able to generate ja phone number', () { + for (var i = 0; i < 20; i++) { + expect( + faker.phoneNumber.ja(), + anyOf( + [ + // // Standard non-geographic 10-digit phone number formats + matches(r'0\d{9}'), + matches(r'0\d{1}-\d{4}-\d{4}'), + matches(r'\(0\d{1}\) \d{4}-\d{4}'), + matches(r'0\d{2}-\d{3}-\d{4}'), + matches(r'\(0\d{2}\) \d{3}-\d{4}'), + matches(r'0\d{3}-\d{2}-\d{4}'), + matches(r'\(0\d{3}\) \d{2}-\d{4}'), + // // Standard non-geographic 11-digit phone number formats + matches(r'0\d{10}'), + matches(r'0\d{1}-\d{5}-\d{4}'), + matches(r'\(0\d{1}\) \d{5}-\d{4}'), + matches(r'0\d{2}-\d{4}-\d{4}'), + matches(r'\(0\d{2}\) \d{4}-\d{4}'), + matches(r'0\d{3}-\d{3}-\d{4}'), + matches(r'\(0\d{3}\) \d{3}-\d{4}'), + // // Standard non-geographic 10-digit phone number formats with country code + matches(r'\+810\d{9}'), + matches(r'\+81-0\d{9}'), + matches(r'\+81 0\d{9}'), + matches(r'\+81-\(0\d{1}\)-\d{4}-\d{4}'), + matches(r'\+81 \(0\d{1}\) \d{4}-\d{4}'), + matches(r'\+81-0\d{2}-\d{3}-\d{4}'), + matches(r'\+81 0\d{2}-\d{3}-\d{4}'), + matches(r'\+81 \(0\d{2}\) \d{3}-\d{4}'), + matches(r'\+81-0\d{3}-\d{2}-\d{4}'), + matches(r'\+81 0\d{3}-\d{2}-\d{4}'), + matches(r'\+81 \(0\d{3}\) \d{2}-\d{4}'), + // // Standard non-geographic 11-digit phone number formats with country code + matches(r'\+810\d{10}'), + matches(r'\+81-0\d{1}-\d{5}-\d{4}'), + matches(r'\+81 0\d{1}-\d{5}-\d{4}'), + matches(r'\+81 \(0\d{1}\) \d{5}-\d{4}'), + matches(r'\+81-0\d{2}-\d{4}-\d{4}'), + matches(r'\+81 0\d{2}-\d{4}-\d{4}'), + matches(r'\+81 \(0\d{2}\) \d{4}-\d{4}'), + matches(r'\+81-0\d{3}-\d{3}-\d{4}'), + matches(r'\+81 0\d{3}-\d{3}-\d{4}'), + matches(r'\+81 \(0\d{3}\) \d{3}-\d{4}'), + ], + ), + ); + } + }); + }); }