From 7e1b7fab8255c8204addef17733ef3588e0806e0 Mon Sep 17 00:00:00 2001 From: Shruti Shahi Date: Sun, 6 Jul 2025 23:01:55 +0530 Subject: [PATCH] moved phone number and email validation functions to appropriate folders --- src/index.js | 26 ++------------------------ src/validators/email.js | 11 ++++++++++- src/validators/index.js | 3 ++- src/validators/phone.js | 11 ++++++++++- 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/index.js b/src/index.js index 60c4fb3..de9bca3 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,5 @@ +import { validateEmail, validatePhoneNumber } from './validators/index.js'; + /** * Validates a form identified by the given form ID. * @@ -90,30 +92,6 @@ function validateForm(formId) { } } -/** - * Validate an email address. - * - * @param {string} email - * @returns {boolean} - * - * TODO: Move to separate file for email validation if it'll be. - */ -function validateEmail(email) { - const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; - return re.test(String(email).toLowerCase()); -} -/** - * Validate a phone number. - * - * @param {string} phone - * @returns {boolean} - * - * TODO: Move to separate file for phone validation if it'll be. - */ -function validatePhoneNumber(phone) { - const re = /^[0-9\s()+-]{6,20}$/; - return re.test(String(phone)); -} export default validateForm; diff --git a/src/validators/email.js b/src/validators/email.js index de897f5..818a3f1 100644 --- a/src/validators/email.js +++ b/src/validators/email.js @@ -1 +1,10 @@ -// TODO: add email validation function here. \ No newline at end of file +/** + * Validate an email address. + * + * @param {string} email + * @returns {boolean} + */ +export function validateEmail(email) { + const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + return re.test(String(email).toLowerCase()); +} \ No newline at end of file diff --git a/src/validators/index.js b/src/validators/index.js index 98e9e96..57f48c3 100644 --- a/src/validators/index.js +++ b/src/validators/index.js @@ -1 +1,2 @@ -// TODO: export all validators function here. \ No newline at end of file +export { validateEmail } from './email.js'; +export { validatePhoneNumber } from './phone.js'; \ No newline at end of file diff --git a/src/validators/phone.js b/src/validators/phone.js index 5307620..46804c2 100644 --- a/src/validators/phone.js +++ b/src/validators/phone.js @@ -1 +1,10 @@ -// TODO: add phone validation function here. \ No newline at end of file +/** + * Validate a phone number. + * + * @param {string} phone + * @returns {boolean} + */ +export function validatePhoneNumber(phone) { + const re = /^[0-9\s()+-]{6,20}$/; + return re.test(String(phone)); +} \ No newline at end of file