Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghana phone numbers (with fixes, all tests passed) #927

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 76 additions & 76 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var phones = {
'el-GR': /^(\+?30|0)?(69\d{8})$/,
'en-AU': /^(\+?61|0)4\d{8}$/,
'en-GB': /^(\+?44|0)7\d{9}$/,
'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/,
'en-HK': /^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/,
'en-IN': /^(\+?91|0)?[6789]\d{9}$/,
'en-KE': /^(\+?254|0)?[7]\d{8}$/,
Expand Down
1 change: 1 addition & 0 deletions src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const phones = {
'el-GR': /^(\+?30|0)?(69\d{8})$/,
'en-AU': /^(\+?61|0)4\d{8}$/,
'en-GB': /^(\+?44|0)7\d{9}$/,
'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/,
'en-HK': /^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/,
'en-IN': /^(\+?91|0)?[6789]\d{9}$/,
'en-KE': /^(\+?254|0)?[7]\d{8}$/,
Expand Down
31 changes: 31 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -3673,6 +3673,37 @@ describe('Validators', () => {
'04123456789',
],
},
{
locale: 'en-GH',
valid: [
'0202345671',
'0502345671',
'0242345671',
'0542345671',
'0272345671',
'0572345671',
'0262345671',
'0562345671',
'0232345671',
'0282345671',
'+233202345671',
'+233502345671',
'+233242345671',
'+233542345671',
'+233272345671',
'+233572345671',
'+233262345671',
'+233562345671',
'+233232345671',
'+233282345671',
],
invalid: [
'082123',
'232345671',
'0292345671',
'+233292345671',
],
},
{
locale: 'en-HK',
valid: [
Expand Down
24 changes: 22 additions & 2 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}

function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];

if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}

return (hint === "string" ? String : Number)(input);
}

function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");

return typeof key === "symbol" ? key : String(key);
}

function _addElementPlacement(element, placements, silent) {
var keys = placements[element.placement];

Expand Down Expand Up @@ -102,8 +121,8 @@ function _toElementDescriptor(elementObject) {
throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"');
}

var key = elementObject.key;
if (typeof key !== "string" && typeof key !== "symbol") key = String(key);
var key = _toPropertyKey(elementObject.key);

var placement = String(elementObject.placement);

if (placement !== "static" && placement !== "prototype" && placement !== "own") {
Expand Down Expand Up @@ -1362,6 +1381,7 @@ var phones = {
'el-GR': /^(\+?30|0)?(69\d{8})$/,
'en-AU': /^(\+?61|0)4\d{8}$/,
'en-GB': /^(\+?44|0)7\d{9}$/,
'en-GH': /^(\+233|0)(20|50|24|54|27|57|26|56|23|28)\d{7}$/,
'en-HK': /^(\+?852\-?)?[456789]\d{3}\-?\d{4}$/,
'en-IN': /^(\+?91|0)?[6789]\d{9}$/,
'en-KE': /^(\+?254|0)?[7]\d{8}$/,
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.