Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions src/lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const phones = {
'ar-SY': /^(!?(\+?963)|0)?9\d{8}$/,
'ar-TN': /^(\+?216)?[2459]\d{7}$/,
'az-AZ': /^(\+994|0)(10|5[015]|7[07]|99)\d{7}$/,
'ar-QA': /^(\+?974\s?)?([3567]\d{3})(\s|-)?\d{4}$/,
'bs-BA': /^((((\+|00)3876)|06))((([0-3]|[5-6])\d{6})|(4\d{7}))$/,
'be-BY': /^(\+?375)?(24|25|29|33|44)\d{7}$/,
'bg-BG': /^(\+?359|0)?8[789]\d{7}$/,
Expand Down Expand Up @@ -173,6 +174,7 @@ phones['zh-MO'] = phones['en-MO'];
phones['ga-IE'] = phones['en-IE'];
phones['fr-CH'] = phones['de-CH'];
phones['it-CH'] = phones['fr-CH'];
phones['en-QA'] = phones['ar-QA'];

export default function isMobilePhone(str, locale, options) {
assertString(str);
Expand Down
102 changes: 102 additions & 0 deletions test/validators/isMobilePhone.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import test from '../testFunctions';

describe('isMobilePhone', () => {
describe('is Qatar phone number', () => {
it('should validate Qatar phone numbers', () => {
test({
validator: 'isMobilePhone',
args: ['ar-QA'],
valid: [
'+97435551234',
'+97455551234',
'+97465551234',
'+97475551234',
'35551234',
'55551234',
'65551234',
'75551234',

],
invalid: [
'+97445551234',
'45551234',
'035551234',
'+97405551234',
'25551234',
'95551234',
'+9745555123',
'+974555512345',
'+9745555abcd',
'+97355551234',
'',
'+974',
],
});
});

it('should validate Qatar phone numbers in strict mode', () => {
test({
validator: 'isMobilePhone',
args: ['ar-QA', { strictMode: true }],
valid: [
'+97435551234',
'+97455551234',
'+97465551234',
'+97475551234',
'+974 55551234',
],
invalid: [
'+97445551234',
'35551234',
'55551234',
'035551234',
'+97405551234',
'+9745555123',
'+974555512345',
'+97355551234',
],
});
});

it('should validate when using multiple locales including Qatar', () => {
test({
validator: 'isMobilePhone',
args: ['ar-QA'],
valid: [
'+97435551234',
'+97455551234',
'35551234',
'55551234',
],
invalid: [
'+97445551234',
'+9125551234',
'25551234',
'+13005551234',
'+9745555123',
'',
],
});
});

it('should validate when using any locale', () => {
test({
validator: 'isMobilePhone',
args: [],
valid: [
'+97455551234',
'+13055551234',
'+447123456789',
'+61412345678',
],
invalid: [
'12345',
'abc',
'',
'+9745555123',
'+97445551234',
],
});
});
});
});