-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from wim07101993/phone-number
feat(phone-number): implemented phone number support
- Loading branch information
Showing
4 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:faker/faker.dart'; | ||
|
||
class PhoneNumber { | ||
static const usPhoneNumberPatterns = [ | ||
// Standard 10-digit phone number formats | ||
'##########', | ||
'##########', | ||
'###-###-####', | ||
'###-###-####', | ||
// Optional 10-digit local phone number format | ||
'(###)###-####', | ||
'(###)###-####', | ||
// Non-standard 10-digit phone number format | ||
'###.###.####', | ||
'###.###.####', | ||
// Standard 10-digit phone number format with extensions | ||
'###-###-####x###', | ||
'###-###-####x####', | ||
'###-###-####x#####', | ||
// Optional 10-digit local phone number format with extensions | ||
'(###)###-####x###', | ||
'(###)###-####x####', | ||
'(###)###-####x#####', | ||
// Non-standard 10-digit phone number format with extensions | ||
'###.###.####x###', | ||
'###.###.####x####', | ||
'###.###.####x#####', | ||
// Standard 11-digit phone number format | ||
'+1-###-###-####', | ||
'001-###-###-####', | ||
// Standard 11-digit phone number format with extensions | ||
'+1-###-###-####x###', | ||
'+1-###-###-####x####', | ||
'+1-###-###-####x#####', | ||
'001-###-###-####x###', | ||
'001-###-###-####x####', | ||
'001-###-###-####x#####', | ||
]; | ||
|
||
const PhoneNumber(); | ||
|
||
String us() => random.fromPattern(usPhoneNumberPatterns); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:faker/faker.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
var faker = Faker(); | ||
|
||
group('us', () { | ||
test('should be able to generate us phone number', () { | ||
for (var i = 0; i < 20; i++) { | ||
expect( | ||
faker.phoneNumber.us(), | ||
anyOf( | ||
[ | ||
// Standard 10-digit phone number formats | ||
matches(r'\d{10}'), | ||
matches(r'\d{3}-\d{3}-\d{3}'), | ||
// Optional 10-digit local phone number format | ||
matches(r'\(\d{3}\)\d{3}-\d{3}'), | ||
// Non-standard 10-digit phone number format | ||
matches(r'\d{3}.\d{3}.\d{4}'), | ||
// Standard 10-digit phone number format with extensions | ||
matches(r'\d{3}-\d{3}-\d{4}x\d{3}'), | ||
matches(r'\d{3}-\d{3}-\d{4}x\d{4}'), | ||
matches(r'\d{3}-\d{3}-\d{4}x\d{5}'), | ||
// Optional 10-digit local phone number format with extensions | ||
matches(r'\(\d{3}\)\d{3}-\d{4}x\d{3}'), | ||
matches(r'\(\d{3}\)\d{3}-\d{4}x\d{4}'), | ||
matches(r'\(\d{3}\)\d{3}-\d{4}x\d{5}'), | ||
// Non-standard 10-digit phone number format with extensions | ||
matches(r'\d{3}.\d{3}.\d{4}x\d{3}'), | ||
matches(r'\d{3}.\d{3}.\d{4}x\d{4}'), | ||
matches(r'\d{3}.\d{3}.\d{4}x\d{5}'), | ||
// Standard 11-digit phone number format | ||
matches(r'\+1-\d{3}-\d{3}-\d{4}'), | ||
matches(r'001-\d{3}-\d{3}-\d{4}'), | ||
// Standard 11-digit phone number format with extensions | ||
matches(r'\+1-\d{3}-\d{3}-\d{4}x\d{3}'), | ||
matches(r'\+1-\d{3}-\d{3}-\d{4}x\d{4}'), | ||
matches(r'\+1-\d{3}-\d{3}-\d{4}x\d{5}'), | ||
matches(r'001-\d{3}-\d{3}-\d{4}x\d{3}'), | ||
matches(r'001-\d{3}-\d{3}-\d{4}x\d{4}'), | ||
matches(r'001-\d{3}-\d{3}-\d{4}x\d{5}'), | ||
], | ||
), | ||
); | ||
} | ||
}); | ||
}); | ||
} |