diff --git a/packages/utils/src/validation/methods.test.ts b/packages/utils/src/validation/methods.test.ts index ca28d05b1a3..195f181b07c 100644 --- a/packages/utils/src/validation/methods.test.ts +++ b/packages/utils/src/validation/methods.test.ts @@ -1,67 +1,40 @@ -import { validFirstName, validLastName, validEmail, validPhone } from './methods'; -import { - validNames, - invalidNames, - validEmails, - invalidEmails, - validPhones, - invalidPhones, -} from './testValues'; +import { validFirstName, validLastName, validEmail } from './methods'; +import { validNames, invalidNames, validEmails, invalidEmails } from './testValues'; describe('methods', () => { describe('validFirstName', () => { // Test valid values - test.each(validNames)( - '"%s" should be an acceptable first name', - (value: string) => expect(validFirstName(value)).toBe(true), + test.each(validNames)('"%s" should be an acceptable first name', (value: string) => + expect(validFirstName(value)).toBe(true), ); // Test invalid values - test.each(invalidNames)( - '"%s" should not be an acceptable first name', - (value: string) => expect(validFirstName(value)).toBe(false), + test.each(invalidNames)('"%s" should not be an acceptable first name', (value: string) => + expect(validFirstName(value)).toBe(false), ); }); describe('validLastName', () => { // Test valid values - test.each(validNames)( - '"%s" should be an acceptable last name', - (value: string) => expect(validLastName(value)).toBe(true), + test.each(validNames)('"%s" should be an acceptable last name', (value: string) => + expect(validLastName(value)).toBe(true), ); // Test invalid values - test.each(invalidNames)( - '"%s" should not be an acceptable last name', - (value: string) => expect(validLastName(value)).toBe(false), + test.each(invalidNames)('"%s" should not be an acceptable last name', (value: string) => + expect(validLastName(value)).toBe(false), ); }); describe('validEmail', () => { // Test valid values - test.each(validEmails)( - '"%s" should be an acceptable email', - (value: string) => expect(validEmail(value)).toBe(true), + test.each(validEmails)('"%s" should be an acceptable email', (value: string) => + expect(validEmail(value)).toBe(true), ); // Test invalid values - test.each(invalidEmails)( - '"%s" should not be an acceptable email', - (value: string) => expect(validEmail(value)).toBe(false), - ); - }); - - describe('validPhone', () => { - // Test valid values - test.each(validPhones)( - '"%s" should be an acceptable phone', - (value: string) => expect(validPhone(value)).toBe(true), - ); - - // Test invalid values - test.each(invalidPhones)( - '"%s" should not be an acceptable phone', - (value: string) => expect(validPhone(value)).toBe(false), + test.each(invalidEmails)('"%s" should not be an acceptable email', (value: string) => + expect(validEmail(value)).toBe(false), ); }); }); diff --git a/packages/utils/src/validation/methods.ts b/packages/utils/src/validation/methods.ts index 1e6212ecd6b..876036354b9 100644 --- a/packages/utils/src/validation/methods.ts +++ b/packages/utils/src/validation/methods.ts @@ -36,10 +36,3 @@ export const validEmail: Function = getValidationMethod(EMAIL); * @returns {boolean} */ export const validDomain: Function = getValidationMethod(DOMAIN); - -/** - * Check that a given value is a valid phone number - * @param {string} value - * @returns {boolean} - */ -export const validPhone: Function = getValidationMethod(PHONE); diff --git a/packages/utils/src/validation/regexp.ts b/packages/utils/src/validation/regexp.ts index a4454c1a495..47b21cfac1b 100644 --- a/packages/utils/src/validation/regexp.ts +++ b/packages/utils/src/validation/regexp.ts @@ -1,13 +1,6 @@ -/* eslint-disable no-useless-escape */ - -export const PHONE = - /^((?:\+[\d().-]*\d[\d().-]*|[0-9A-F*#().-]*[0-9A-F*#][0-9A-F*#().-]*(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*;phone-context=(?:\+[\d().-]*\d[\d().-]*|(?:[a-z0-9]\.|[a-z0-9][a-z0-9-]*[a-z0-9]\.)*(?:[a-z]|[a-z][a-z0-9-]*[a-z0-9])))(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*(?:,(?:\+[\d().-]*\d[\d().-]*|[0-9A-F*#().-]*[0-9A-F*#][0-9A-F*#().-]*(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*;?)*)*)$/; - export const EMAIL = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i; export const NAME = /^[^\~!@#$%^&*()|+=?;:",<>\{\}\[\]\\\/¤€¨£°§]*$/i; export const DOMAIN = /^[^\~!#$%^&*()|+=?;:",<>\{\}\[\]\\\/¤€¨£°§]*$/i; - -/* eslint-enable no-useless-escape */ diff --git a/packages/utils/src/validation/testValues.ts b/packages/utils/src/validation/testValues.ts index 448644a5a69..42bf34fa75a 100644 --- a/packages/utils/src/validation/testValues.ts +++ b/packages/utils/src/validation/testValues.ts @@ -46,14 +46,3 @@ export const validEmails: Array = [ ]; export const invalidEmails: Array = ['john', 'john@', 'john @', 'john\\@re']; - -// Phones -export const validPhones: Array = ['+33102030405']; - -export const invalidPhones: Array = [ - 'john', - 'john@', - 'john @', - 'sarah@something.fr', - 'Fred', -];