From 9ae99c42680a589b9601dcfdd74b2f260a2e637a Mon Sep 17 00:00:00 2001 From: ihlaya Date: Sat, 12 Oct 2024 01:20:07 +0300 Subject: [PATCH 1/4] feat: Monaco phone validation --- src/lib/isMobilePhone.js | 25 ++- test/validators.test.js | 367 ++++++++------------------------------- 2 files changed, 87 insertions(+), 305 deletions(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index e9932caa7..dd34d20b2 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -34,7 +34,8 @@ const phones = { 'dv-MV': /^(\+?960)?(7[2-9]|9[1-9])\d{5}$/, 'el-GR': /^(\+?30|0)?6(8[5-9]|9(?![26])[0-9])\d{7}$/, 'el-CY': /^(\+?357?)?(9(9|6)\d{6})$/, - 'en-AI': /^(\+?1|0)264(?:2(35|92)|4(?:6[1-2]|76|97)|5(?:3[6-9]|8[1-4])|7(?:2(4|9)|72))\d{4}$/, + 'en-AI': + /^(\+?1|0)264(?:2(35|92)|4(?:6[1-2]|76|97)|5(?:3[6-9]|8[1-4])|7(?:2(4|9)|72))\d{4}$/, 'en-AU': /^(\+?61|0)4\d{8}$/, 'en-AG': /^(?:\+1|1)268(?:464|7(?:1[3-9]|[28]\d|3[0246]|64|7[0-689]))\d{4}$/, 'en-BM': /^(\+?1)?441(((3|7)\d{6}$)|(5[0-3][0-9]\d{4}$)|(59\d{5}$))/, @@ -56,7 +57,8 @@ const phones = { 'en-LS': /^(\+?266)(22|28|57|58|59|27|52)\d{6}$/, 'en-MT': /^(\+?356|0)?(99|79|77|21|27|22|25)[0-9]{6}$/, 'en-MU': /^(\+?230|0)?\d{8}$/, - 'en-MW': /^(\+?265|0)(((77|88|31|99|98|21)\d{7})|(((111)|1)\d{6})|(32000\d{4}))$/, + 'en-MW': + /^(\+?265|0)(((77|88|31|99|98|21)\d{7})|(((111)|1)\d{6})|(32000\d{4}))$/, 'en-NA': /^(\+?264|0)(6|8)\d{7}$/, 'en-NG': /^(\+?234|0)?[789]\d{9}$/, 'en-NZ': /^(\+?64|0)[28]\d{7,9}$/, @@ -68,7 +70,8 @@ const phones = { 'en-SL': /^(\+?232|0)\d{8}$/, 'en-TZ': /^(\+?255|0)?[67]\d{8}$/, 'en-UG': /^(\+?256|0)?[7]\d{8}$/, - 'en-US': /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/, + 'en-US': + /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/, 'en-ZA': /^(\+?27|0)\d{9}$/, 'en-ZM': /^(\+?26)?09[567]\d{7}$/, 'en-ZW': /^(\+263)[0-9]{9}$/, @@ -105,12 +108,14 @@ const phones = { 'fr-GF': /^(\+?594|0|00594)[67]\d{8}$/, 'fr-GP': /^(\+?590|0|00590)[67]\d{8}$/, 'fr-MQ': /^(\+?596|0|00596)[67]\d{8}$/, + 'fr-MC': /^(?:\+?377|0)?(9[0-9]{7}|6[0-9]{7})$/, 'fr-PF': /^(\+?689)?8[789]\d{6}$/, 'fr-RE': /^(\+?262|0|00262)[67]\d{8}$/, 'fr-WF': /^(\+681)?\d{6}$/, 'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/, 'hu-HU': /^(\+?36|06)(20|30|31|50|70)\d{7}$/, - 'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/, + 'id-ID': + /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/, 'ir-IR': /^(\+98|0)?9\d{9}$/, 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/, 'it-SM': /^((\+378)|(0549)|(\+390549)|(\+3780549))?6\d{5,9}$/, @@ -119,7 +124,8 @@ const phones = { 'kk-KZ': /^(\+?7|8)?7\d{9}$/, 'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/, 'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/, - 'ky-KG': /^(\+996\s?)?(22[0-9]|50[0-9]|55[0-9]|70[0-9]|75[0-9]|77[0-9]|880|990|995|996|997|998)\s?\d{3}\s?\d{3}$/, + 'ky-KG': + /^(\+996\s?)?(22[0-9]|50[0-9]|55[0-9]|70[0-9]|75[0-9]|77[0-9]|880|990|995|996|997|998)\s?\d{3}\s?\d{3}$/, 'lt-LT': /^(\+370|8)\d{8}$/, 'lv-LV': /^(\+?371)2\d{7}$/, 'mg-MG': /^((\+?261|0)(2|3)\d)?\d{7}$/, @@ -134,14 +140,16 @@ const phones = { 'nl-AW': /^(\+)?297(56|59|64|73|74|99)\d{5}$/, 'nn-NO': /^(\+?47)?[49]\d{7}$/, 'pl-PL': /^(\+?48)? ?([5-8]\d|45) ?\d{3} ?\d{2} ?\d{2}$/, - 'pt-BR': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[1-9]{1}\d{3}\-?\d{4}))$/, + 'pt-BR': + /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[1-9]{1}\d{3}\-?\d{4}))$/, 'pt-PT': /^(\+?351)?9[1236]\d{7}$/, 'pt-AO': /^(\+244)\d{9}$/, 'ro-MD': /^(\+?373|0)((6(0|1|2|6|7|8|9))|(7(6|7|8|9)))\d{6}$/, 'ro-RO': /^(\+?40|0)\s?7\d{2}(\/|\s|\.|-)?\d{3}(\s|\.|-)?\d{3}$/, 'ru-RU': /^(\+?7|8)?9\d{9}$/, 'si-LK': /^(?:0|94|\+94)?(7(0|1|2|4|5|6|7|8)( |-)?)\d{7}$/, - 'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/, + 'sl-SI': + /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/, 'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/, 'so-SO': /^(\+?252|0)((6[0-9])\d{7}|(7[1-9])\d{7})$/, 'sq-AL': /^(\+355|0)6[789]\d{6}$/, @@ -153,7 +161,8 @@ const phones = { 'tk-TM': /^(\+993|993|8)\d{8}$/, 'uk-UA': /^(\+?38)?0(50|6[36-8]|7[357]|9[1-9])\d{7}$/, 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/, - 'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, + 'vi-VN': + /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, 'zh-CN': /^((\+|00)86)?(1[3-9]|9[28])\d{9}$/, 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/, 'dz-BT': /^(\+?975|0)?(17|16|77|02)\d{6}$/, diff --git a/test/validators.test.js b/test/validators.test.js index 31a36d029..666839065 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -7440,22 +7440,11 @@ describe('Validators', () => { '016329712', '97517265559', ], - invalid: [ - '', - '9898347255', - '+96326626262', - '963372', - '0114152198', - ], + invalid: ['', '9898347255', '+96326626262', '963372', '0114152198'], }, { locale: 'ar-OM', - valid: [ - '+96891212121', - '0096899999999', - '93112211', - '99099009', - ], + valid: ['+96891212121', '0096899999999', '93112211', '99099009'], invalid: [ '+96890212121', '0096890999999', @@ -7469,12 +7458,7 @@ describe('Validators', () => { }, { locale: 'ar-PS', - valid: [ - '+970563459876', - '970592334218', - '0566372345', - '0598273583', - ], + valid: ['+970563459876', '970592334218', '0566372345', '0598273583'], invalid: [ '+9759029487', '97059123456789', @@ -7496,13 +7480,7 @@ describe('Validators', () => { '0944549710', '0962655597', ], - invalid: [ - '12345', - '', - '+9639626626262', - '+963332210972', - '0114152198', - ], + invalid: ['12345', '', '+9639626626262', '+963332210972', '0114152198'], }, { locale: 'ar-SA', @@ -7513,22 +7491,11 @@ describe('Validators', () => { '596578654', '572655597', ], - invalid: [ - '12345', - '', - '+9665626626262', - '+96633221097', - '0114152198', - ], + invalid: ['12345', '', '+9665626626262', '+96633221097', '0114152198'], }, { locale: 'ar-SD', - valid: [ - '0128652312', - '+249919425113', - '249123212345', - '0993212345', - ], + valid: ['0128652312', '+249919425113', '249123212345', '0993212345'], invalid: [ '12345', '', @@ -7541,33 +7508,13 @@ describe('Validators', () => { }, { locale: 'ar-TN', - valid: [ - '23456789', - '+21623456789', - '21623456789', - ], - invalid: [ - '12345', - '75200123', - '+216512345678', - '13520459', - '85479520', - ], + valid: ['23456789', '+21623456789', '21623456789'], + invalid: ['12345', '75200123', '+216512345678', '13520459', '85479520'], }, { locale: 'bg-BG', - valid: [ - '+359897123456', - '+359898888888', - '0897123123', - ], - invalid: [ - '', - '0898123', - '+359212555666', - '18001234567', - '12125559999', - ], + valid: ['+359897123456', '+359898888888', '0897123123'], + invalid: ['', '0898123', '+359212555666', '18001234567', '12125559999'], }, { locale: 'bn-BD', @@ -7701,24 +7648,12 @@ describe('Validators', () => { '+4372876', '06434908989562345', ], - invalid: [ - '167612345678', - '1234', - '064349089895623459', - ], + invalid: ['167612345678', '1234', '064349089895623459'], }, { locale: 'hu-HU', - valid: [ - '06301234567', - '+36201234567', - '06701234567', - ], - invalid: [ - '1234', - '06211234567', - '+3620123456', - ], + valid: ['06301234567', '+36201234567', '06701234567'], + invalid: ['1234', '06211234567', '+3620123456'], }, { locale: 'mz-MZ', @@ -7884,12 +7819,7 @@ describe('Validators', () => { '+886-987123456', '886-987123456', ], - invalid: [ - '12345', - '', - 'Vml2YW11cyBmZXJtZtesting123', - '0-987123456', - ], + invalid: ['12345', '', 'Vml2YW11cyBmZXJtZtesting123', '0-987123456'], }, { local: 'en-LS', @@ -7912,12 +7842,7 @@ describe('Validators', () => { }, { locale: 'en-BM', - valid: [ - '+14417974653', - '14413986653', - '4415370973', - '+14415005489', - ], + valid: ['+14417974653', '14413986653', '4415370973', '+14415005489'], invalid: [ '85763287', '+14412020436', @@ -7955,11 +7880,7 @@ describe('Validators', () => { }, { locale: 'en-ZA', - valid: [ - '0821231234', - '+27821231234', - '27821231234', - ], + valid: ['0821231234', '+27821231234', '27821231234'], invalid: [ '082123', '08212312345', @@ -7970,11 +7891,7 @@ describe('Validators', () => { }, { locale: 'en-AU', - valid: [ - '61404111222', - '+61411222333', - '0417123456', - ], + valid: ['61404111222', '+61411222333', '0417123456'], invalid: [ '082123', '08212312345', @@ -8010,11 +7927,7 @@ describe('Validators', () => { '441481123456', '441481789123', ], - invalid: [ - '999', - '+441481123456789', - '+447123456789', - ], + invalid: ['999', '+441481123456789', '+447123456789'], }, { locale: 'en-GH', @@ -8042,21 +7955,11 @@ describe('Validators', () => { '+233592349493', '0550298219', ], - invalid: [ - '082123', - '232345671', - '0292345671', - '+233292345671', - ], + invalid: ['082123', '232345671', '0292345671', '+233292345671'], }, { locale: 'en-GY', - valid: [ - '+5926121234', - '06121234', - '06726381', - '+5926726381', - ], + valid: ['+5926121234', '06121234', '06726381', '+5926726381'], invalid: [ '5926121234', '6121234', @@ -8079,12 +7982,7 @@ describe('Validators', () => { '9123 4567', '852-91234567', ], - invalid: [ - '999', - '+852-912345678', - '123456789', - '+852-1234-56789', - ], + invalid: ['999', '+852-912345678', '123456789', '+852-1234-56789'], }, { locale: 'en-MO', @@ -8133,12 +8031,7 @@ describe('Validators', () => { }, { locale: 'en-JM', - valid: [ - '+8761021234', - '8761211234', - '8763511274', - '+8764511274', - ], + valid: ['+8761021234', '8761211234', '8763511274', '+8764511274'], invalid: [ '999', '+876102123422', @@ -8159,12 +8052,7 @@ describe('Validators', () => { '+254110456794', '254198452389', ], - invalid: [ - '999', - '+25489032', - '123456789', - '+254800723845', - ], + invalid: ['999', '+25489032', '123456789', '+254800723845'], }, { locale: 'fr-CF', @@ -8188,17 +8076,11 @@ describe('Validators', () => { '022452389', '+236772345678', '+236700456794', - ], }, { locale: 'en-KI', - valid: [ - '+68673140000', - '68673059999', - '+68663000000', - '68663019999', - ], + valid: ['+68673140000', '68673059999', '+68663000000', '68663019999'], invalid: [ '+68653000000', '68664019999', @@ -8209,16 +8091,8 @@ describe('Validators', () => { }, { locale: 'en-MT', - valid: [ - '+35699000000', - '+35679000000', - '99000000', - ], - invalid: [ - '356', - '+35699000', - '+35610000000', - ], + valid: ['+35699000000', '+35679000000', '99000000'], + invalid: ['356', '+35699000', '+35610000000'], }, { locale: 'en-PH', @@ -8498,6 +8372,23 @@ describe('Validators', () => { '+59661245789', ], }, + { + locale: 'fr-MC', + valid: [ + '+37791234567', + '061234567', + '+37761234567', + '091234567', + '+37793234567', + ], + invalid: [ + '+3379912345', + '377123456', + '0991234567', + '+3778112345', + '069123', + ], + }, { locale: 'fr-RE', valid: [ @@ -8568,7 +8459,6 @@ describe('Validators', () => { '022452389', '+681772345678', '+681700456794', - ], }, { @@ -8657,11 +8547,7 @@ describe('Validators', () => { }, { locale: 'en-GB', - valid: [ - '447789345856', - '+447861235675', - '07888814488', - ], + valid: ['447789345856', '+447861235675', '07888814488'], invalid: [ '67699567', '0773894868', @@ -8799,12 +8685,7 @@ describe('Validators', () => { }, { locale: 'ru-RU', - valid: [ - '+79676338855', - '79676338855', - '89676338855', - '9676338855', - ], + valid: ['+79676338855', '79676338855', '89676338855', '9676338855'], invalid: [ '12345', '', @@ -8857,12 +8738,7 @@ describe('Validators', () => { }, { locale: 'en-NZ', - valid: [ - '+6427987035', - '642240512347', - '0293981646', - '029968425', - ], + valid: ['+6427987035', '642240512347', '0293981646', '029968425'], invalid: [ '12345', '', @@ -8877,11 +8753,7 @@ describe('Validators', () => { }, { locale: 'en-MU', - valid: [ - '+23012341234', - '12341234', - '012341234', - ], + valid: ['+23012341234', '12341234', '012341234'], invalid: [ '41234', '', @@ -9022,12 +8894,7 @@ describe('Validators', () => { }, { locale: 'es-CL', - valid: [ - '+56733875615', - '56928590234', - '0928590294', - '0208590294', - ], + valid: ['+56733875615', '56928590234', '0928590294', '0208590294'], invalid: [ '1234', '+5633875615', @@ -9082,12 +8949,7 @@ describe('Validators', () => { }, { locale: 'es-CU', - valid: [ - '+5351234567', - '005353216547', - '51234567', - '53214567', - ], + valid: ['+5351234567', '005353216547', '51234567', '53214567'], invalid: [ '1234', '+5341234567', @@ -9230,12 +9092,7 @@ describe('Validators', () => { }, { locale: 'es-PA', - valid: [ - '+5076784565', - '+5074321557', - '5073331112', - '+50723431212', - ], + valid: ['+5076784565', '+5074321557', '5073331112', '+50723431212'], invalid: [ '+50755555', '+207123456', @@ -9305,12 +9162,7 @@ describe('Validators', () => { }, { locale: 'es-UY', - valid: [ - '+59899123456', - '099123456', - '+59894654321', - '091111111', - ], + valid: ['+59899123456', '099123456', '+59894654321', '091111111'], invalid: [ '54321', 'montevideo', @@ -9322,16 +9174,8 @@ describe('Validators', () => { }, { locale: 'es-VE', - valid: [ - '+582125457765', - '+582125458053', - '+584125458053', - ], - invalid: [ - '+585129934395', - '+58212993439', - '', - ], + valid: ['+582125457765', '+582125458053', '+584125458053'], + invalid: ['+585129934395', '+58212993439', ''], }, { locale: 'et-EE', @@ -9617,12 +9461,7 @@ describe('Validators', () => { }, { locale: 'ir-IR', - valid: [ - '09023818688', - '09123809999', - '+989023818688', - '+989103923523', - ], + valid: ['09023818688', '09123809999', '+989023818688', '+989103923523'], invalid: [ '19023818688', '323254', @@ -9639,11 +9478,7 @@ describe('Validators', () => { '+39 310 7688449', '+39 3339847632', ], - invalid: [ - '011 7387545', - '12345', - '+45 345 6782395', - ], + invalid: ['011 7387545', '12345', '+45 345 6782395'], }, { locale: 'fr-BE', @@ -9890,10 +9725,7 @@ describe('Validators', () => { }, { locale: 'lt-LT', - valid: [ - '+37051234567', - '851234567', - ], + valid: ['+37051234567', '851234567'], invalid: [ '+65740 123 456', '', @@ -10074,12 +9906,7 @@ describe('Validators', () => { }, { locale: 'kk-KZ', - valid: [ - '+77254716212', - '77254716212', - '87254716212', - '7254716212', - ], + valid: ['+77254716212', '77254716212', '87254716212', '7254716212'], invalid: [ '12345', '', @@ -10114,17 +9941,8 @@ describe('Validators', () => { }, { locale: 'th-TH', - valid: [ - '0912345678', - '+66912345678', - '66912345678', - ], - invalid: [ - '99123456789', - '12345', - '67812345623', - '081234567891', - ], + valid: ['0912345678', '+66912345678', '66912345678'], + invalid: ['99123456789', '12345', '67812345623', '081234567891'], }, { locale: 'tk-TM', @@ -10135,20 +9953,11 @@ describe('Validators', () => { '99312183399', '812391717', ], - invalid: [ - '12345', - '+99412495154', - '99412495154', - '998900066506', - ], + invalid: ['12345', '+99412495154', '99412495154', '998900066506'], }, { locale: 'en-SL', - valid: [ - '+23274560591', - '23274560591', - '074560591', - ], + valid: ['+23274560591', '23274560591', '074560591'], invalid: [ '0745605912', '12345', @@ -10207,10 +10016,7 @@ describe('Validators', () => { }, { locale: 'de-LU', - valid: [ - '601123456', - '+352601123456', - ], + valid: ['601123456', '+352601123456'], invalid: [ 'NaN', '791234', @@ -10231,13 +10037,7 @@ describe('Validators', () => { '+390549612345678', '+37805496123456789', ], - invalid: [ - '61234567890', - '6123', - '1234567', - '+49123456', - 'NotANumber', - ], + invalid: ['61234567890', '6123', '1234567', '+49123456', 'NotANumber'], }, { locale: 'so-SO', @@ -10262,10 +10062,7 @@ describe('Validators', () => { }, { locale: 'sq-AL', - valid: [ - '067123456', - '+35567123456', - ], + valid: ['067123456', '+35567123456'], invalid: [ '67123456', '06712345', @@ -10277,23 +10074,12 @@ describe('Validators', () => { }, { locale: 'ca-AD', - valid: [ - '+376312345', - '312345', - ], - invalid: [ - '31234', - '31234567', - '512345', - 'NotANumber', - ], + valid: ['+376312345', '312345'], + invalid: ['31234', '31234567', '512345', 'NotANumber'], }, { locale: 'pt-AO', - valid: [ - '+244911123432', - '+244123091232', - ], + valid: ['+244911123432', '+244123091232'], invalid: [ '+2449111234321', '31234', @@ -10304,10 +10090,7 @@ describe('Validators', () => { }, { locale: 'lv-LV', - valid: [ - '+37121234567', - '37121234567', - ], + valid: ['+37121234567', '37121234567'], invalid: [ '+37201234567', '+3754321', @@ -10550,11 +10333,7 @@ describe('Validators', () => { }, { locale: 'ar-YE', - valid: [ - '737198225', - '733111355', - '+967700990270', - ], + valid: ['737198225', '733111355', '+967700990270'], invalid: [ '+5032136663', '21346663', @@ -10591,11 +10370,7 @@ describe('Validators', () => { }, { locale: 'fa-AF', - valid: [ - '0511231231', - '+93511231231', - '+93281234567', - ], + valid: ['0511231231', '+93511231231', '+93281234567'], invalid: [ '212528812312123', '+212-5290-12312', @@ -10632,7 +10407,6 @@ describe('Validators', () => { '+211931234567', '+211901234567', '+211991234567', - ], }, { @@ -10655,7 +10429,6 @@ describe('Validators', () => { 'This should fail', '5021931234567', '+50281234567', - ], }, ]; From 36feb1452cbfa0f9dbd8091d1384800fa9d1f208 Mon Sep 17 00:00:00 2001 From: ihlaya Date: Sat, 12 Oct 2024 01:23:40 +0300 Subject: [PATCH 2/4] feat: update isMobilePhone readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c1cadb9f..f2067240e 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ Validator | Description **isMailtoURI(str, [, options])** | check if the string is a [Mailto URI format][Mailto URI Format].

`options` is an object of validating emails inside the URI (check `isEmail`s options for details). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **isMimeType(str)** | check if the string matches to a valid [MIME type][MIME Type] format. -**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,

`locale` is either an array of locales (e.g. `['sk-SK', 'sr-RS']`) OR one of `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-EH', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'az-AZ', 'az-LB', 'az-LY', 'be-BY', 'bg-BG', 'bn-BD', 'bs-BA', 'ca-AD', 'cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'de-LU', 'dv-MV', 'dz-BT', 'el-CY', 'el-GR', 'en-AG', 'en-AI', 'en-AU', 'en-BM', 'en-BS', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-IE', 'en-IN', 'en-JM', 'en-KE', 'en-KI', 'en-KN', 'en-LS', 'en-MO', 'en-MT', 'en-MU', 'en-MW', 'en-NG', 'en-NZ', 'en-PG', 'en-PH', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-SS', 'en-TZ', 'en-UG', 'en-US', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-EC', 'es-ES', 'es-GT','es-HN', 'es-MX', 'es-NI', 'es-PA', 'es-PE', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-AF', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-BJ', 'fr-CD', 'fr-CF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-PF', 'fr-RE', 'fr-WF', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'ir-IR', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'ky-KG', 'lt-LT', 'mg-MG', 'mn-MN', 'ms-MY', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-AW', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-AO', 'pt-BR', 'pt-PT', 'ro-Md', 'ro-RO', 'ru-RU', 'si-LK', 'sk-SK', 'sl-SI', 'so-SO', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tk-TM', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW']` OR defaults to `'any'`. If 'any' or a falsey value is used, function will check if any of the locales match).

`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`. +**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,

`locale` is either an array of locales (e.g. `['sk-SK', 'sr-RS']`) OR one of `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-EH', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'az-AZ', 'az-LB', 'az-LY', 'be-BY', 'bg-BG', 'bn-BD', 'bs-BA', 'ca-AD', 'cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'de-LU', 'dv-MV', 'dz-BT', 'el-CY', 'el-GR', 'en-AG', 'en-AI', 'en-AU', 'en-BM', 'en-BS', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-IE', 'en-IN', 'en-JM', 'en-KE', 'en-KI', 'en-KN', 'en-LS', 'en-MO', 'en-MT', 'en-MU', 'en-MW', 'en-NG', 'en-NZ', 'en-PG', 'en-PH', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-SS', 'en-TZ', 'en-UG', 'en-US', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-EC', 'es-ES', 'es-GT','es-HN', 'es-MX', 'es-NI', 'es-PA', 'es-PE', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-AF', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-BJ', 'fr-CD', 'fr-CF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-MC', 'fr-PF', 'fr-RE', 'fr-WF', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'ir-IR', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'ky-KG', 'lt-LT', 'mg-MG', 'mn-MN', 'ms-MY', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-AW', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-AO', 'pt-BR', 'pt-PT', 'ro-Md', 'ro-RO', 'ru-RU', 'si-LK', 'sk-SK', 'sl-SI', 'so-SO', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tk-TM', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW']` OR defaults to `'any'`. If 'any' or a falsey value is used, function will check if any of the locales match).

`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`. **isMongoId(str)** | check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid]. **isMultibyte(str)** | check if the string contains one or more multibyte chars. **isNumeric(str [, options])** | check if the string contains only numbers.

`options` is an object which defaults to `{ no_symbols: false }` it also has `locale` as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`locale` determines the decimal separator and is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'eo', 'es-ES', 'fr-FR', 'fr-CA', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`. From 313cde99ad69d17621415785e74b9c2556da8da6 Mon Sep 17 00:00:00 2001 From: ihlaya Date: Sat, 12 Oct 2024 20:44:22 +0300 Subject: [PATCH 3/4] fix: linter --- src/lib/isMobilePhone.js | 24 +-- test/validators.test.js | 350 +++++++++++++++++++++++++++++++++------ 2 files changed, 305 insertions(+), 69 deletions(-) diff --git a/src/lib/isMobilePhone.js b/src/lib/isMobilePhone.js index dd34d20b2..21d840fb5 100644 --- a/src/lib/isMobilePhone.js +++ b/src/lib/isMobilePhone.js @@ -34,8 +34,7 @@ const phones = { 'dv-MV': /^(\+?960)?(7[2-9]|9[1-9])\d{5}$/, 'el-GR': /^(\+?30|0)?6(8[5-9]|9(?![26])[0-9])\d{7}$/, 'el-CY': /^(\+?357?)?(9(9|6)\d{6})$/, - 'en-AI': - /^(\+?1|0)264(?:2(35|92)|4(?:6[1-2]|76|97)|5(?:3[6-9]|8[1-4])|7(?:2(4|9)|72))\d{4}$/, + 'en-AI': /^(\+?1|0)264(?:2(35|92)|4(?:6[1-2]|76|97)|5(?:3[6-9]|8[1-4])|7(?:2(4|9)|72))\d{4}$/, 'en-AU': /^(\+?61|0)4\d{8}$/, 'en-AG': /^(?:\+1|1)268(?:464|7(?:1[3-9]|[28]\d|3[0246]|64|7[0-689]))\d{4}$/, 'en-BM': /^(\+?1)?441(((3|7)\d{6}$)|(5[0-3][0-9]\d{4}$)|(59\d{5}$))/, @@ -57,8 +56,7 @@ const phones = { 'en-LS': /^(\+?266)(22|28|57|58|59|27|52)\d{6}$/, 'en-MT': /^(\+?356|0)?(99|79|77|21|27|22|25)[0-9]{6}$/, 'en-MU': /^(\+?230|0)?\d{8}$/, - 'en-MW': - /^(\+?265|0)(((77|88|31|99|98|21)\d{7})|(((111)|1)\d{6})|(32000\d{4}))$/, + 'en-MW': /^(\+?265|0)(((77|88|31|99|98|21)\d{7})|(((111)|1)\d{6})|(32000\d{4}))$/, 'en-NA': /^(\+?264|0)(6|8)\d{7}$/, 'en-NG': /^(\+?234|0)?[789]\d{9}$/, 'en-NZ': /^(\+?64|0)[28]\d{7,9}$/, @@ -70,8 +68,7 @@ const phones = { 'en-SL': /^(\+?232|0)\d{8}$/, 'en-TZ': /^(\+?255|0)?[67]\d{8}$/, 'en-UG': /^(\+?256|0)?[7]\d{8}$/, - 'en-US': - /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/, + 'en-US': /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/, 'en-ZA': /^(\+?27|0)\d{9}$/, 'en-ZM': /^(\+?26)?09[567]\d{7}$/, 'en-ZW': /^(\+263)[0-9]{9}$/, @@ -114,8 +111,7 @@ const phones = { 'fr-WF': /^(\+681)?\d{6}$/, 'he-IL': /^(\+972|0)([23489]|5[012345689]|77)[1-9]\d{6}$/, 'hu-HU': /^(\+?36|06)(20|30|31|50|70)\d{7}$/, - 'id-ID': - /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/, + 'id-ID': /^(\+?62|0)8(1[123456789]|2[1238]|3[1238]|5[12356789]|7[78]|9[56789]|8[123456789])([\s?|\d]{5,11})$/, 'ir-IR': /^(\+98|0)?9\d{9}$/, 'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/, 'it-SM': /^((\+378)|(0549)|(\+390549)|(\+3780549))?6\d{5,9}$/, @@ -124,8 +120,7 @@ const phones = { 'kk-KZ': /^(\+?7|8)?7\d{9}$/, 'kl-GL': /^(\+?299)?\s?\d{2}\s?\d{2}\s?\d{2}$/, 'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/, - 'ky-KG': - /^(\+996\s?)?(22[0-9]|50[0-9]|55[0-9]|70[0-9]|75[0-9]|77[0-9]|880|990|995|996|997|998)\s?\d{3}\s?\d{3}$/, + 'ky-KG': /^(\+996\s?)?(22[0-9]|50[0-9]|55[0-9]|70[0-9]|75[0-9]|77[0-9]|880|990|995|996|997|998)\s?\d{3}\s?\d{3}$/, 'lt-LT': /^(\+370|8)\d{8}$/, 'lv-LV': /^(\+?371)2\d{7}$/, 'mg-MG': /^((\+?261|0)(2|3)\d)?\d{7}$/, @@ -140,16 +135,14 @@ const phones = { 'nl-AW': /^(\+)?297(56|59|64|73|74|99)\d{5}$/, 'nn-NO': /^(\+?47)?[49]\d{7}$/, 'pl-PL': /^(\+?48)? ?([5-8]\d|45) ?\d{3} ?\d{2} ?\d{2}$/, - 'pt-BR': - /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[1-9]{1}\d{3}\-?\d{4}))$/, + 'pt-BR': /^((\+?55\ ?[1-9]{2}\ ?)|(\+?55\ ?\([1-9]{2}\)\ ?)|(0[1-9]{2}\ ?)|(\([1-9]{2}\)\ ?)|([1-9]{2}\ ?))((\d{4}\-?\d{4})|(9[1-9]{1}\d{3}\-?\d{4}))$/, 'pt-PT': /^(\+?351)?9[1236]\d{7}$/, 'pt-AO': /^(\+244)\d{9}$/, 'ro-MD': /^(\+?373|0)((6(0|1|2|6|7|8|9))|(7(6|7|8|9)))\d{6}$/, 'ro-RO': /^(\+?40|0)\s?7\d{2}(\/|\s|\.|-)?\d{3}(\s|\.|-)?\d{3}$/, 'ru-RU': /^(\+?7|8)?9\d{9}$/, 'si-LK': /^(?:0|94|\+94)?(7(0|1|2|4|5|6|7|8)( |-)?)\d{7}$/, - 'sl-SI': - /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/, + 'sl-SI': /^(\+386\s?|0)(\d{1}\s?\d{3}\s?\d{2}\s?\d{2}|\d{2}\s?\d{3}\s?\d{3})$/, 'sk-SK': /^(\+?421)? ?[1-9][0-9]{2} ?[0-9]{3} ?[0-9]{3}$/, 'so-SO': /^(\+?252|0)((6[0-9])\d{7}|(7[1-9])\d{7})$/, 'sq-AL': /^(\+355|0)6[789]\d{6}$/, @@ -161,8 +154,7 @@ const phones = { 'tk-TM': /^(\+993|993|8)\d{8}$/, 'uk-UA': /^(\+?38)?0(50|6[36-8]|7[357]|9[1-9])\d{7}$/, 'uz-UZ': /^(\+?998)?(6[125-79]|7[1-69]|88|9\d)\d{7}$/, - 'vi-VN': - /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, + 'vi-VN': /^((\+?84)|0)((3([2-9]))|(5([25689]))|(7([0|6-9]))|(8([1-9]))|(9([0-9])))([0-9]{7})$/, 'zh-CN': /^((\+|00)86)?(1[3-9]|9[28])\d{9}$/, 'zh-TW': /^(\+?886\-?|0)?9\d{8}$/, 'dz-BT': /^(\+?975|0)?(17|16|77|02)\d{6}$/, diff --git a/test/validators.test.js b/test/validators.test.js index 666839065..a8611a094 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -7440,11 +7440,22 @@ describe('Validators', () => { '016329712', '97517265559', ], - invalid: ['', '9898347255', '+96326626262', '963372', '0114152198'], + invalid: [ + '', + '9898347255', + '+96326626262', + '963372', + '0114152198', + ], }, { locale: 'ar-OM', - valid: ['+96891212121', '0096899999999', '93112211', '99099009'], + valid: [ + '+96891212121', + '0096899999999', + '93112211', + '99099009', + ], invalid: [ '+96890212121', '0096890999999', @@ -7458,7 +7469,12 @@ describe('Validators', () => { }, { locale: 'ar-PS', - valid: ['+970563459876', '970592334218', '0566372345', '0598273583'], + valid: [ + '+970563459876', + '970592334218', + '0566372345', + '0598273583', + ], invalid: [ '+9759029487', '97059123456789', @@ -7480,7 +7496,13 @@ describe('Validators', () => { '0944549710', '0962655597', ], - invalid: ['12345', '', '+9639626626262', '+963332210972', '0114152198'], + invalid: [ + '12345', + '', + '+9639626626262', + '+963332210972', + '0114152198', + ], }, { locale: 'ar-SA', @@ -7491,11 +7513,22 @@ describe('Validators', () => { '596578654', '572655597', ], - invalid: ['12345', '', '+9665626626262', '+96633221097', '0114152198'], + invalid: [ + '12345', + '', + '+9665626626262', + '+96633221097', + '0114152198', + ], }, { locale: 'ar-SD', - valid: ['0128652312', '+249919425113', '249123212345', '0993212345'], + valid: [ + '0128652312', + '+249919425113', + '249123212345', + '0993212345', + ], invalid: [ '12345', '', @@ -7508,13 +7541,33 @@ describe('Validators', () => { }, { locale: 'ar-TN', - valid: ['23456789', '+21623456789', '21623456789'], - invalid: ['12345', '75200123', '+216512345678', '13520459', '85479520'], + valid: [ + '23456789', + '+21623456789', + '21623456789', + ], + invalid: [ + '12345', + '75200123', + '+216512345678', + '13520459', + '85479520', + ], }, { locale: 'bg-BG', - valid: ['+359897123456', '+359898888888', '0897123123'], - invalid: ['', '0898123', '+359212555666', '18001234567', '12125559999'], + valid: [ + '+359897123456', + '+359898888888', + '0897123123', + ], + invalid: [ + '', + '0898123', + '+359212555666', + '18001234567', + '12125559999', + ], }, { locale: 'bn-BD', @@ -7648,12 +7701,24 @@ describe('Validators', () => { '+4372876', '06434908989562345', ], - invalid: ['167612345678', '1234', '064349089895623459'], + invalid: [ + '167612345678', + '1234', + '064349089895623459', + ], }, { locale: 'hu-HU', - valid: ['06301234567', '+36201234567', '06701234567'], - invalid: ['1234', '06211234567', '+3620123456'], + valid: [ + '06301234567', + '+36201234567', + '06701234567', + ], + invalid: [ + '1234', + '06211234567', + '+3620123456', + ], }, { locale: 'mz-MZ', @@ -7819,7 +7884,12 @@ describe('Validators', () => { '+886-987123456', '886-987123456', ], - invalid: ['12345', '', 'Vml2YW11cyBmZXJtZtesting123', '0-987123456'], + invalid: [ + '12345', + '', + 'Vml2YW11cyBmZXJtZtesting123', + '0-987123456', + ], }, { local: 'en-LS', @@ -7842,7 +7912,12 @@ describe('Validators', () => { }, { locale: 'en-BM', - valid: ['+14417974653', '14413986653', '4415370973', '+14415005489'], + valid: [ + '+14417974653', + '14413986653', + '4415370973', + '+14415005489', + ], invalid: [ '85763287', '+14412020436', @@ -7880,7 +7955,11 @@ describe('Validators', () => { }, { locale: 'en-ZA', - valid: ['0821231234', '+27821231234', '27821231234'], + valid: [ + '0821231234', + '+27821231234', + '27821231234', + ], invalid: [ '082123', '08212312345', @@ -7891,7 +7970,11 @@ describe('Validators', () => { }, { locale: 'en-AU', - valid: ['61404111222', '+61411222333', '0417123456'], + valid: [ + '61404111222', + '+61411222333', + '0417123456', + ], invalid: [ '082123', '08212312345', @@ -7927,7 +8010,11 @@ describe('Validators', () => { '441481123456', '441481789123', ], - invalid: ['999', '+441481123456789', '+447123456789'], + invalid: [ + '999', + '+441481123456789', + '+447123456789', + ], }, { locale: 'en-GH', @@ -7955,11 +8042,21 @@ describe('Validators', () => { '+233592349493', '0550298219', ], - invalid: ['082123', '232345671', '0292345671', '+233292345671'], + invalid: [ + '082123', + '232345671', + '0292345671', + '+233292345671', + ], }, { locale: 'en-GY', - valid: ['+5926121234', '06121234', '06726381', '+5926726381'], + valid: [ + '+5926121234', + '06121234', + '06726381', + '+5926726381', + ], invalid: [ '5926121234', '6121234', @@ -7982,7 +8079,12 @@ describe('Validators', () => { '9123 4567', '852-91234567', ], - invalid: ['999', '+852-912345678', '123456789', '+852-1234-56789'], + invalid: [ + '999', + '+852-912345678', + '123456789', + '+852-1234-56789', + ], }, { locale: 'en-MO', @@ -8031,7 +8133,12 @@ describe('Validators', () => { }, { locale: 'en-JM', - valid: ['+8761021234', '8761211234', '8763511274', '+8764511274'], + valid: [ + '+8761021234', + '8761211234', + '8763511274', + '+8764511274', + ], invalid: [ '999', '+876102123422', @@ -8052,7 +8159,12 @@ describe('Validators', () => { '+254110456794', '254198452389', ], - invalid: ['999', '+25489032', '123456789', '+254800723845'], + invalid: [ + '999', + '+25489032', + '123456789', + '+254800723845', + ], }, { locale: 'fr-CF', @@ -8076,11 +8188,17 @@ describe('Validators', () => { '022452389', '+236772345678', '+236700456794', + ], }, { locale: 'en-KI', - valid: ['+68673140000', '68673059999', '+68663000000', '68663019999'], + valid: [ + '+68673140000', + '68673059999', + '+68663000000', + '68663019999', + ], invalid: [ '+68653000000', '68664019999', @@ -8091,8 +8209,16 @@ describe('Validators', () => { }, { locale: 'en-MT', - valid: ['+35699000000', '+35679000000', '99000000'], - invalid: ['356', '+35699000', '+35610000000'], + valid: [ + '+35699000000', + '+35679000000', + '99000000', + ], + invalid: [ + '356', + '+35699000', + '+35610000000', + ], }, { locale: 'en-PH', @@ -8459,6 +8585,7 @@ describe('Validators', () => { '022452389', '+681772345678', '+681700456794', + ], }, { @@ -8547,7 +8674,11 @@ describe('Validators', () => { }, { locale: 'en-GB', - valid: ['447789345856', '+447861235675', '07888814488'], + valid: [ + '447789345856', + '+447861235675', + '07888814488', + ], invalid: [ '67699567', '0773894868', @@ -8685,7 +8816,12 @@ describe('Validators', () => { }, { locale: 'ru-RU', - valid: ['+79676338855', '79676338855', '89676338855', '9676338855'], + valid: [ + '+79676338855', + '79676338855', + '89676338855', + '9676338855', + ], invalid: [ '12345', '', @@ -8738,7 +8874,12 @@ describe('Validators', () => { }, { locale: 'en-NZ', - valid: ['+6427987035', '642240512347', '0293981646', '029968425'], + valid: [ + '+6427987035', + '642240512347', + '0293981646', + '029968425', + ], invalid: [ '12345', '', @@ -8753,7 +8894,11 @@ describe('Validators', () => { }, { locale: 'en-MU', - valid: ['+23012341234', '12341234', '012341234'], + valid: [ + '+23012341234', + '12341234', + '012341234', + ], invalid: [ '41234', '', @@ -8894,7 +9039,12 @@ describe('Validators', () => { }, { locale: 'es-CL', - valid: ['+56733875615', '56928590234', '0928590294', '0208590294'], + valid: [ + '+56733875615', + '56928590234', + '0928590294', + '0208590294', + ], invalid: [ '1234', '+5633875615', @@ -8949,7 +9099,12 @@ describe('Validators', () => { }, { locale: 'es-CU', - valid: ['+5351234567', '005353216547', '51234567', '53214567'], + valid: [ + '+5351234567', + '005353216547', + '51234567', + '53214567', + ], invalid: [ '1234', '+5341234567', @@ -9092,7 +9247,12 @@ describe('Validators', () => { }, { locale: 'es-PA', - valid: ['+5076784565', '+5074321557', '5073331112', '+50723431212'], + valid: [ + '+5076784565', + '+5074321557', + '5073331112', + '+50723431212', + ], invalid: [ '+50755555', '+207123456', @@ -9162,7 +9322,12 @@ describe('Validators', () => { }, { locale: 'es-UY', - valid: ['+59899123456', '099123456', '+59894654321', '091111111'], + valid: [ + '+59899123456', + '099123456', + '+59894654321', + '091111111', + ], invalid: [ '54321', 'montevideo', @@ -9174,8 +9339,16 @@ describe('Validators', () => { }, { locale: 'es-VE', - valid: ['+582125457765', '+582125458053', '+584125458053'], - invalid: ['+585129934395', '+58212993439', ''], + valid: [ + '+582125457765', + '+582125458053', + '+584125458053', + ], + invalid: [ + '+585129934395', + '+58212993439', + '', + ], }, { locale: 'et-EE', @@ -9461,7 +9634,12 @@ describe('Validators', () => { }, { locale: 'ir-IR', - valid: ['09023818688', '09123809999', '+989023818688', '+989103923523'], + valid: [ + '09023818688', + '09123809999', + '+989023818688', + '+989103923523', + ], invalid: [ '19023818688', '323254', @@ -9478,7 +9656,11 @@ describe('Validators', () => { '+39 310 7688449', '+39 3339847632', ], - invalid: ['011 7387545', '12345', '+45 345 6782395'], + invalid: [ + '011 7387545', + '12345', + '+45 345 6782395', + ], }, { locale: 'fr-BE', @@ -9725,7 +9907,10 @@ describe('Validators', () => { }, { locale: 'lt-LT', - valid: ['+37051234567', '851234567'], + valid: [ + '+37051234567', + '851234567', + ], invalid: [ '+65740 123 456', '', @@ -9906,7 +10091,12 @@ describe('Validators', () => { }, { locale: 'kk-KZ', - valid: ['+77254716212', '77254716212', '87254716212', '7254716212'], + valid: [ + '+77254716212', + '77254716212', + '87254716212', + '7254716212', + ], invalid: [ '12345', '', @@ -9941,8 +10131,17 @@ describe('Validators', () => { }, { locale: 'th-TH', - valid: ['0912345678', '+66912345678', '66912345678'], - invalid: ['99123456789', '12345', '67812345623', '081234567891'], + valid: [ + '0912345678', + '+66912345678', + '66912345678', + ], + invalid: [ + '99123456789', + '12345', + '67812345623', + '081234567891', + ], }, { locale: 'tk-TM', @@ -9953,11 +10152,20 @@ describe('Validators', () => { '99312183399', '812391717', ], - invalid: ['12345', '+99412495154', '99412495154', '998900066506'], + invalid: [ + '12345', + '+99412495154', + '99412495154', + '998900066506', + ], }, { locale: 'en-SL', - valid: ['+23274560591', '23274560591', '074560591'], + valid: [ + '+23274560591', + '23274560591', + '074560591', + ], invalid: [ '0745605912', '12345', @@ -10016,7 +10224,10 @@ describe('Validators', () => { }, { locale: 'de-LU', - valid: ['601123456', '+352601123456'], + valid: [ + '601123456', + '+352601123456', + ], invalid: [ 'NaN', '791234', @@ -10037,7 +10248,13 @@ describe('Validators', () => { '+390549612345678', '+37805496123456789', ], - invalid: ['61234567890', '6123', '1234567', '+49123456', 'NotANumber'], + invalid: [ + '61234567890', + '6123', + '1234567', + '+49123456', + 'NotANumber', + ], }, { locale: 'so-SO', @@ -10062,7 +10279,10 @@ describe('Validators', () => { }, { locale: 'sq-AL', - valid: ['067123456', '+35567123456'], + valid: [ + '067123456', + '+35567123456', + ], invalid: [ '67123456', '06712345', @@ -10074,12 +10294,23 @@ describe('Validators', () => { }, { locale: 'ca-AD', - valid: ['+376312345', '312345'], - invalid: ['31234', '31234567', '512345', 'NotANumber'], + valid: [ + '+376312345', + '312345', + ], + invalid: [ + '31234', + '31234567', + '512345', + 'NotANumber', + ], }, { locale: 'pt-AO', - valid: ['+244911123432', '+244123091232'], + valid: [ + '+244911123432', + '+244123091232', + ], invalid: [ '+2449111234321', '31234', @@ -10090,7 +10321,10 @@ describe('Validators', () => { }, { locale: 'lv-LV', - valid: ['+37121234567', '37121234567'], + valid: [ + '+37121234567', + '37121234567', + ], invalid: [ '+37201234567', '+3754321', @@ -10333,7 +10567,11 @@ describe('Validators', () => { }, { locale: 'ar-YE', - valid: ['737198225', '733111355', '+967700990270'], + valid: [ + '737198225', + '733111355', + '+967700990270', + ], invalid: [ '+5032136663', '21346663', @@ -10370,7 +10608,11 @@ describe('Validators', () => { }, { locale: 'fa-AF', - valid: ['0511231231', '+93511231231', '+93281234567'], + valid: [ + '0511231231', + '+93511231231', + '+93281234567', + ], invalid: [ '212528812312123', '+212-5290-12312', @@ -10407,6 +10649,7 @@ describe('Validators', () => { '+211931234567', '+211901234567', '+211991234567', + ], }, { @@ -10429,6 +10672,7 @@ describe('Validators', () => { 'This should fail', '5021931234567', '+50281234567', + ], }, ]; From 3ddd76338dcc51013e68944fe36d7a3f0a094353 Mon Sep 17 00:00:00 2001 From: Rubin Bhandari Date: Thu, 14 Nov 2024 14:26:57 +0545 Subject: [PATCH 4/4] Update README.md Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f2067240e..41159bf9e 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ Validator | Description **isMailtoURI(str, [, options])** | check if the string is a [Mailto URI format][Mailto URI Format].

`options` is an object of validating emails inside the URI (check `isEmail`s options for details). **isMD5(str)** | check if the string is a MD5 hash.

Please note that you can also use the `isHash(str, 'md5')` function. Keep in mind that MD5 has some collision weaknesses compared to other algorithms (e.g., SHA). **isMimeType(str)** | check if the string matches to a valid [MIME type][MIME Type] format. -**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,

`locale` is either an array of locales (e.g. `['sk-SK', 'sr-RS']`) OR one of `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-EH', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'az-AZ', 'az-LB', 'az-LY', 'be-BY', 'bg-BG', 'bn-BD', 'bs-BA', 'ca-AD', 'cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'de-LU', 'dv-MV', 'dz-BT', 'el-CY', 'el-GR', 'en-AG', 'en-AI', 'en-AU', 'en-BM', 'en-BS', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-IE', 'en-IN', 'en-JM', 'en-KE', 'en-KI', 'en-KN', 'en-LS', 'en-MO', 'en-MT', 'en-MU', 'en-MW', 'en-NG', 'en-NZ', 'en-PG', 'en-PH', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-SS', 'en-TZ', 'en-UG', 'en-US', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-EC', 'es-ES', 'es-GT','es-HN', 'es-MX', 'es-NI', 'es-PA', 'es-PE', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-AF', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-BJ', 'fr-CD', 'fr-CF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MQ', 'fr-MC', 'fr-PF', 'fr-RE', 'fr-WF', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'ir-IR', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'ky-KG', 'lt-LT', 'mg-MG', 'mn-MN', 'ms-MY', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-AW', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-AO', 'pt-BR', 'pt-PT', 'ro-Md', 'ro-RO', 'ru-RU', 'si-LK', 'sk-SK', 'sl-SI', 'so-SO', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tk-TM', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW']` OR defaults to `'any'`. If 'any' or a falsey value is used, function will check if any of the locales match).

`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`. +**isMobilePhone(str [, locale [, options]])** | check if the string is a mobile phone number,

`locale` is either an array of locales (e.g. `['sk-SK', 'sr-RS']`) OR one of `['am-Am', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-EH', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-PS', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'az-AZ', 'az-LB', 'az-LY', 'be-BY', 'bg-BG', 'bn-BD', 'bs-BA', 'ca-AD', 'cs-CZ', 'da-DK', 'de-AT', 'de-CH', 'de-DE', 'de-LU', 'dv-MV', 'dz-BT', 'el-CY', 'el-GR', 'en-AG', 'en-AI', 'en-AU', 'en-BM', 'en-BS', 'en-BW', 'en-CA', 'en-GB', 'en-GG', 'en-GH', 'en-GY', 'en-HK', 'en-IE', 'en-IN', 'en-JM', 'en-KE', 'en-KI', 'en-KN', 'en-LS', 'en-MO', 'en-MT', 'en-MU', 'en-MW', 'en-NG', 'en-NZ', 'en-PG', 'en-PH', 'en-PK', 'en-RW', 'en-SG', 'en-SL', 'en-SS', 'en-TZ', 'en-UG', 'en-US', 'en-ZA', 'en-ZM', 'en-ZW', 'es-AR', 'es-BO', 'es-CL', 'es-CO', 'es-CR', 'es-CU', 'es-DO', 'es-EC', 'es-ES', 'es-GT','es-HN', 'es-MX', 'es-NI', 'es-PA', 'es-PE', 'es-PY', 'es-SV', 'es-UY', 'es-VE', 'et-EE', 'fa-AF', 'fa-IR', 'fi-FI', 'fj-FJ', 'fo-FO', 'fr-BE', 'fr-BF', 'fr-BJ', 'fr-CD', 'fr-CF', 'fr-FR', 'fr-GF', 'fr-GP', 'fr-MC', 'fr-MQ', 'fr-PF', 'fr-RE', 'fr-WF', 'ga-IE', 'he-IL', 'hu-HU', 'id-ID', 'ir-IR', 'it-IT', 'it-SM', 'ja-JP', 'ka-GE', 'kk-KZ', 'kl-GL', 'ko-KR', 'ky-KG', 'lt-LT', 'mg-MG', 'mn-MN', 'ms-MY', 'my-MM', 'mz-MZ', 'nb-NO', 'ne-NP', 'nl-AW', 'nl-BE', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-AO', 'pt-BR', 'pt-PT', 'ro-Md', 'ro-RO', 'ru-RU', 'si-LK', 'sk-SK', 'sl-SI', 'so-SO', 'sq-AL', 'sr-RS', 'sv-SE', 'tg-TJ', 'th-TH', 'tk-TM', 'tr-TR', 'uk-UA', 'uz-UZ', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-MO', 'zh-TW']` OR defaults to `'any'`. If 'any' or a falsey value is used, function will check if any of the locales match).

`options` is an optional object that can be supplied with the following keys: `strictMode`, if this is set to `true`, the mobile phone number must be supplied with the country code and therefore must start with `+`. Locale list is `validator.isMobilePhoneLocales`. **isMongoId(str)** | check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid]. **isMultibyte(str)** | check if the string contains one or more multibyte chars. **isNumeric(str [, options])** | check if the string contains only numbers.

`options` is an object which defaults to `{ no_symbols: false }` it also has `locale` as an option. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).

`locale` determines the decimal separator and is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'eo', 'es-ES', 'fr-FR', 'fr-CA', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']`.