diff --git a/src/formatters/formatToPhone.ts b/src/formatters/formatToPhone.ts index fbd5164..50123e1 100644 --- a/src/formatters/formatToPhone.ts +++ b/src/formatters/formatToPhone.ts @@ -10,7 +10,7 @@ import mapToNumeric from '../helpers/mapToNumeric'; * //=> '(11) 9716-26' * * formatToPhone('11971626799') - * //=> '(11) 9 7162-6799' + * //=> '(11) 97162-6799' * ``` * @param value */ @@ -21,7 +21,7 @@ const formatToPhone = ( .replace(/(\d{1,2})/, '($1') .replace(/(\(\d{2})(\d{1,4})/, '$1) $2') .replace(/( \d{4})(\d{1,4})/, '$1-$2') - .replace(/( \d{1})(\d{3})(?:-)(\d{1})(\d{4})/, '$1 $2$3-$4') + .replace(/( \d{4})(?:-)(\d{1})(\d{4})/, '$1$2-$3') ); export default formatToPhone; diff --git a/src/validators/isPhone.ts b/src/validators/isPhone.ts index 873d9e5..6ebd999 100644 --- a/src/validators/isPhone.ts +++ b/src/validators/isPhone.ts @@ -4,17 +4,17 @@ import isDDD from './isDDD'; * Pattern for common brazilian telephone number formats, optionally with DDI, * DDD and the ninth digit. */ -const PHONE_PATTERN = /^(\+55)? ?\(?(\d{2})?\)? ?9? ?\d{4}[-| ]?\d{4}$/; +const PHONE_PATTERN = /^(\+55)? ?\(?(\d{2})?\)? ?9?\d{4}[-| ]?\d{4}$/; /** * Check if value is a valid brazilian phone number. It can check a wide * variety of formats optionally with DDI, DDD and the ninth digit. * * @example ```js - * isPhone('+55 (11) 9 8273-1182') + * isPhone('+55 (11) 98273-1182') * //=> true * - * isPhone('11 9 8273 1182') + * isPhone('11 98273 1182') * //=> true * * isPhone('1139723768') @@ -23,7 +23,7 @@ const PHONE_PATTERN = /^(\+55)? ?\(?(\d{2})?\)? ?9? ?\d{4}[-| ]?\d{4}$/; * isPhone('(23) 3972-3768') * //=> false * - * isPhone('(13) 6 5093-2093') + * isPhone('(13) 65093-2093') * //=> false * * isPhone('(81) 555 178') diff --git a/test/formatters.test.ts b/test/formatters.test.ts index 2d0359f..3f9ab95 100644 --- a/test/formatters.test.ts +++ b/test/formatters.test.ts @@ -119,7 +119,7 @@ test('formatToPhone', (context) => { context.is(formatToPhone('11'), '(11'); context.is(formatToPhone('11971626'), '(11) 9716-26'); context.is(formatToPhone('1197162679'), '(11) 9716-2679'); - context.is(formatToPhone('11971626799'), '(11) 9 7162-6799'); + context.is(formatToPhone('11971626799'), '(11) 97162-6799'); }); test('formatToRG', (context) => { diff --git a/test/validators.test.ts b/test/validators.test.ts index d091322..770a80d 100644 --- a/test/validators.test.ts +++ b/test/validators.test.ts @@ -80,8 +80,8 @@ test('isDDD', (context) => { }); test('isPhone', (context) => { - context.true(isPhone('+55 (11) 9 8273-1182')); - context.true(isPhone('11 9 8273 1182')); + context.true(isPhone('+55 (11) 98273-1182')); + context.true(isPhone('11 98273 1182')); context.true(isPhone('1139723768')); context.false(isPhone('(23) 3972-3768')); context.false(isPhone('(13) 6 5093-2093'));