Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
26 changes: 2 additions & 24 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { validateEmail, validatePhoneNumber } from './validators/index.js';

/**
* Validates a form identified by the given form ID.
*
Expand Down Expand Up @@ -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;
11 changes: 10 additions & 1 deletion src/validators/email.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
// TODO: add email validation function here.
/**
* Validate an email address.
*
* @param {string} email
* @returns {boolean}
*/
export function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(String(email).toLowerCase());
}
3 changes: 2 additions & 1 deletion src/validators/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// TODO: export all validators function here.
export { validateEmail } from './email.js';
export { validatePhoneNumber } from './phone.js';
11 changes: 10 additions & 1 deletion src/validators/phone.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
// TODO: add phone validation function here.
/**
* 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));
}