diff --git a/public/css/dashboard.css b/public/css/dashboard.css
index 303b46f..71fea48 100644
--- a/public/css/dashboard.css
+++ b/public/css/dashboard.css
@@ -1850,4 +1850,131 @@ tr[data-vaid]:hover {
font-size: 0.75rem;
font-weight: 600;
margin-left: 0.5rem;
+}
+
+
+.payment-option {
+ border: 1px solid #e5e7eb;
+ border-radius: 8px;
+ padding: 16px;
+ cursor: pointer;
+}
+
+.payment-option.selected {
+ border-color: var(--border-color);
+ transition: all 0.3s ease;
+ background: var(--bg-card);
+}
+
+.payment-option:hover {
+ border-color: var(--accent-light);
+}
+
+.payment-option.selected {
+ border-color: var(--accent-color);
+ background-color: rgba(99, 102, 241, 0.1);
+}
+
+[data-theme="dark"] .payment-option.selected {
+ background-color: rgba(99, 102, 241, 0.2);
+}
+
+.payment-option h4 {
+ margin-bottom: 8px;
+ font-size: 16px;
+ color: var(--text-primary);
+}
+
+.payment-option p {
+ font-size: 14px;
+ color: var(--text-secondary);
+}
+
+.payment-details {
+ display: none;
+ margin: 4px 0 16px;
+ padding: 16px;
+ border: 1px solid var(--border-color);
+ border-radius: 8px;
+ transition: all 0.3s ease;
+}
+
+.payment-details.active {
+ display: block;
+ animation: slideDown 0.3s ease-out;
+}
+
+
+.form-group {
+ margin-bottom: 16px;
+ position: relative;
+}
+
+.input-container {
+ position: relative;
+ background-color: var(--bg-secondary);
+ border-radius: 6px;
+ overflow: hidden;
+ padding: 2px 0;
+ border: 1px solid transparent;
+ transition: all 0.3s ease;
+}
+
+.input-container:focus-within {
+ border-color: var(--accent-light);
+ box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
+}
+
+.input-label {
+ position: absolute;
+ left: 12px;
+ top: 50%;
+ transform: translateY(-50%);
+ font-size: 14px;
+ color: var(--text-secondary);
+ transition: all 0.2s ease;
+ pointer-events: none;
+}
+
+.input-field, .select-field {
+ width: 100%;
+ padding: 18px 12px 14px;
+ border: none;
+ background: transparent;
+ outline: none;
+ font-size: 14px;
+ border-radius: 6px;
+ color: var(--text-primary);
+ transition: all 0.3s ease;
+}
+
+[data-theme="dark"] .input-field, [data-theme="dark"] .select-field {
+ background-color: #ffffff1a;
+}
+
+.input-field::placeholder {
+ color: var(--text-muted);
+}
+
+.select-field {
+ appearance: none;
+ background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
+ background-repeat: no-repeat;
+ background-position: right 12px center;
+ background-size: 16px;
+ border-radius: 6px;
+}
+
+[data-theme="dark"] .select-field {
+ background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23d1d5db' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
+}
+
+.input-field:focus + .input-label,
+.input-field:not(:placeholder-shown) + .input-label,
+.select-field:focus + .input-label,
+.select-field:valid + .input-label {
+ top: 2px;
+ font-size: 12px;
+ transform: none;
+ color: var(--accent-light);
}
\ No newline at end of file
diff --git a/public/js/va-client-register.js b/public/js/va-client-register.js
index 1e31d69..23b6c77 100644
--- a/public/js/va-client-register.js
+++ b/public/js/va-client-register.js
@@ -491,10 +491,11 @@ async function validateStep(step) {
}
} else if (step === 1) {
const email = document.getElementById('email').value;
- const companyName = document.getElementById('company-name').value;
+ const firstName = document.getElementById('first-name').value;
+ const lastName = document.getElementById('last-name').value;
const password = document.getElementById('password').value;
const confirmPassword = document.getElementById('confirmPassword').value;
- if (!validateEmail(email) && !companyName && !password && !confirmPassword) {
+ if (!validateEmail(email) && !firstName && !lastName && !password && !confirmPassword) {
isValid = false;
showError('Fields are Required', null, step);
let requiredFields1 = form.querySelectorAll('[required]');
@@ -518,9 +519,14 @@ async function validateStep(step) {
isValid = false;
}
}
- if (!companyName) {
+ if (!firstName) {
isValid = false;
- showError('Company / Client Name is Required', null, step);
+ showError('First Name is Required', null, step);
+ return isValid;
+ }
+ if (!lastName) {
+ isValid = false;
+ showError('Last Name is Required', null, step);
return isValid;
}
@@ -627,7 +633,8 @@ function getFormId(step) {
function saveStepData(step) {
switch(step) {
case 1:
- formData.userDetails.name = document.getElementById('company-name').value;
+ formData.userDetails.firstName = document.getElementById('first-name').value;
+ formData.userDetails.lastName = document.getElementById('last-name').value;
formData.userDetails.email = document.getElementById('email').value;
formData.userDetails.password = document.getElementById('password').value;
break;
@@ -1085,7 +1092,7 @@ document.addEventListener('DOMContentLoaded', function() {
// Handle use business address checkbox
document.getElementById('use-business-address').addEventListener('change', function() {
if (this.checked) {
- document.getElementById('billing-name').value = formData.userDetails.name || '';
+ document.getElementById('billing-name').value = formData.userDetails.firstName || '';
document.getElementById('billing-address').value = formData.userDetails.address || '';
document.getElementById('billing-city').value = formData.userDetails.city || '';
document.getElementById('billing-state').value = formData.userDetails.state || '';
@@ -1258,13 +1265,13 @@ function preventNumbers(event) {
return false;
}
-// Function to validate company/client name
-function validateCompanyName(input) {
- const errorElement = document.getElementById('company-name-error');
+// Function to validate first name
+function validateFirstName(input) {
+ const errorElement = document.getElementById('first-name-error');
const value = input.value;
// Check various invalid patterns
- const validationResult = validateCompanyNameContent(value);
+ const validationResult = validateFirstNameContent(value);
if (!validationResult.isValid && value.trim().length > 0) {
errorElement.textContent = validationResult.message;
@@ -1278,16 +1285,16 @@ function validateCompanyName(input) {
}
}
-function validateCompanyNameContent(companyName) {
- const trimmed = companyName.trim();
+function validateFirstNameContent(firstName) {
+ const trimmed = firstName.trim();
if (trimmed.length === 0) {
- return { isValid: false, message: 'Company name is required' };
+ return { isValid: false, message: 'First name is required' };
}
// Check minimum length
if (trimmed.length < 2) {
- return { isValid: false, message: 'Company name must be at least 2 characters' };
+ return { isValid: false, message: 'First name must be at least 2 characters' };
}
// Remove whitespace for content analysis
@@ -1295,25 +1302,112 @@ function validateCompanyNameContent(companyName) {
// Check if contains only special characters
if (/^[^a-zA-Z0-9]+$/.test(content)) {
- return { isValid: false, message: 'Company name cannot be only special characters' };
+ return { isValid: false, message: 'First name cannot be only special characters' };
}
// Check if contains at least some valid content (letters or numbers)
if (!/[a-zA-Z0-9]/.test(content)) {
- return { isValid: false, message: 'Company name must contain letters or numbers' };
+ return { isValid: false, message: 'First name must contain letters or numbers' };
}
// Optional: Check for excessive special characters (more than 50%)
const specialCharCount = (content.match(/[^a-zA-Z0-9]/g) || []).length;
if (specialCharCount > content.length / 2) {
- return { isValid: false, message: 'Company name contains too many special characters' };
+ return { isValid: false, message: 'First name contains too many special characters' };
}
return { isValid: true, message: '' };
}
// Function to prevent invalid character input in real-time
-function preventInvalidCompanyChars(event) {
+function preventInvalidFirstNameChars(event) {
+ const charCode = event.which ? event.which : event.keyCode;
+ const key = event.key;
+
+ // Allow: letters, numbers, spaces, hyphens, apostrophes, ampersands, periods, commas
+ // Also allow common editing keys
+ if ((charCode >= 65 && charCode <= 90) || // A-Z
+ (charCode >= 97 && charCode <= 122) || // a-z
+ (charCode >= 48 && charCode <= 57) || // 0-9
+ charCode === 32 || // space
+ charCode === 45 || // hyphen
+ charCode === 39 || // apostrophe
+ charCode === 38 || // ampersand (&)
+ charCode === 46 || // period (.)
+ charCode === 44 || // comma (,)
+ charCode === 8 || // backspace
+ charCode === 9 || // tab
+ charCode === 37 || // left arrow
+ charCode === 39 || // right arrow
+ charCode === 16 || // shift
+ charCode === 17 || // ctrl
+ charCode === 18 || // alt
+ charCode === 91 || // cmd (Mac)
+ /^[a-zA-Z0-9\s\-'&.,]$/.test(key)) { // allowed characters
+ return true;
+ }
+
+ // Prevent invalid characters
+ event.preventDefault();
+ return false;
+}
+
+// Function to validate last name
+function validateLastName(input) {
+ const errorElement = document.getElementById('last-name-error');
+ const value = input.value;
+
+ // Check various invalid patterns
+ const validationResult = validateLastNameContent(value);
+
+ if (!validationResult.isValid && value.trim().length > 0) {
+ errorElement.textContent = validationResult.message;
+ errorElement.style.display = 'block';
+ input.classList.add('field-error');
+ return false;
+ } else {
+ errorElement.style.display = 'none';
+ input.classList.remove('field-error');
+ return true;
+ }
+}
+
+function validateLastNameContent(lastName) {
+ const trimmed = lastName.trim();
+
+ if (trimmed.length === 0) {
+ return { isValid: false, message: 'Last name is required' };
+ }
+
+ // Check minimum length
+ if (trimmed.length < 2) {
+ return { isValid: false, message: 'Last name must be at least 2 characters' };
+ }
+
+ // Remove whitespace for content analysis
+ const content = trimmed.replace(/\s/g, '');
+
+ // Check if contains only special characters
+ if (/^[^a-zA-Z0-9]+$/.test(content)) {
+ return { isValid: false, message: 'Last name cannot be only special characters' };
+ }
+
+ // Check if contains at least some valid content (letters or numbers)
+ if (!/[a-zA-Z0-9]/.test(content)) {
+ return { isValid: false, message: 'Last name must contain letters or numbers' };
+ }
+
+ // Optional: Check for excessive special characters (more than 50%)
+ const specialCharCount = (content.match(/[^a-zA-Z0-9]/g) || []).length;
+ if (specialCharCount > content.length / 2) {
+ return { isValid: false, message: 'Last name contains too many special characters' };
+ }
+
+ return { isValid: true, message: '' };
+}
+
+// Function to prevent invalid character input in real-time
+function preventInvalidLastNameChars(event) {
const charCode = event.which ? event.which : event.keyCode;
const key = event.key;
diff --git a/src/controllers/client/vaClient.controller.js b/src/controllers/client/vaClient.controller.js
index 25c3307..87695cc 100644
--- a/src/controllers/client/vaClient.controller.js
+++ b/src/controllers/client/vaClient.controller.js
@@ -25,10 +25,10 @@ async function va_register_client(req, res) {
try {
const payload = req.body || {};
const { userDetails } = payload;
- if (!userDetails || !userDetails.email || !userDetails.name || !userDetails.password) {
+ if (!userDetails || !userDetails.email || !userDetails.firstName || !userDetails.lastName || !userDetails.password) {
return res.status(400).json({
success: false,
- message: "Missing required fields: name, email, and password are required"
+ message: "Missing required fields: firstName, lastName, email, and password are required"
});
}
diff --git a/src/models/vaModel.js b/src/models/vaModel.js
index d585f87..6d1fdc4 100644
--- a/src/models/vaModel.js
+++ b/src/models/vaModel.js
@@ -136,6 +136,12 @@ const clientDetailsSchema = new Schema({
name: {
type: String,
},
+ firstName: {
+ type: String,
+ },
+ lastName: {
+ type: String,
+ },
email: {
type: String,
required: true,
diff --git a/src/services/salesforce.service.js b/src/services/salesforce.service.js
index b5acc62..78d4d9a 100644
--- a/src/services/salesforce.service.js
+++ b/src/services/salesforce.service.js
@@ -7,10 +7,8 @@ class SalesforceService {
async registerClientInSalesforce(clientData, _id) {
try {
const url = `${process.env.SF_DOCTRACKER_API_URL}/services/apexrest/docva/api/client`;
-
// Extract only the required data for Salesforce
const salesforcePayload = this.prepareSalesforcePayload(clientData, _id);
-
logger.info(`SalesforceService - Sending client data to Salesforce: ${clientData.userDetails.email}`);
const response = await authFetch(url, {
@@ -21,12 +19,12 @@ class SalesforceService {
body: JSON.stringify(salesforcePayload),
timeout: 30000, // 30 seconds timeout
});
-
logger.info(`SalesforceService - Client registered successfully in Salesforce: ${clientData.userDetails.email}`);
+
return response.data;
} catch (error) {
logger.error(`SalesforceService - Error registering client in Salesforce: ${error.message}`);
-
+
if (error.response) {
// Salesforce returned an error response
logger.error(`SalesforceService - Salesforce API error: ${error.response.status} - ${JSON.stringify(error.response.data)}`);
@@ -44,11 +42,12 @@ class SalesforceService {
prepareSalesforcePayload(clientData, _id) {
const { userDetails } = clientData;
-
+
return {
userDetails: {
_id: _id,
- name: userDetails.name,
+ firstName: userDetails.firstName,
+ lastName: userDetails.lastName,
email: userDetails.email.toLowerCase(),
address: userDetails.address || null,
city: userDetails.city || null,
diff --git a/src/services/vaClient.service.js b/src/services/vaClient.service.js
index 563fc26..a55deff 100644
--- a/src/services/vaClient.service.js
+++ b/src/services/vaClient.service.js
@@ -75,7 +75,7 @@ class VaClientService {
// Define allowed fields for update (excluding password)
const allowedFields = [
- "name", "address", "city", "state", "zip",
+ "firstName", "lastName", "address", "city", "state", "zip",
"billingName", "billingEmail", "billingAddress", "billingCity",
"billingState", "billingZip", "position", "signatoryName",
"signatoryEmail", "paymentMethod", "bankName", "accountNumber",
@@ -271,7 +271,9 @@ class VaClientService {
return {
userDetails: {
- name: userDetails.name,
+ firstName: userDetails.firstName,
+ lastName: userDetails.lastName,
+ name: `${userDetails.firstName} ${userDetails.lastName}`,
email: userDetails.email.toLowerCase(),
password: hashedPassword,
address: userDetails.address || null,
diff --git a/views/client/dashboard-profile.ejs b/views/client/dashboard-profile.ejs
index 8dcb40b..b656b2a 100644
--- a/views/client/dashboard-profile.ejs
+++ b/views/client/dashboard-profile.ejs
@@ -136,9 +136,13 @@
-
+
-
+
+
+
+
+
@@ -335,6 +446,47 @@
clearErrorMessages();
}
+ // Bank Details Modal Functions
+ function openBankDetailsModal() {
+ const modal = document.getElementById('bankDetailsModal');
+ modal.style.display = 'flex';
+ document.body.style.overflow = 'hidden';
+
+ // Clear form and errors
+ document.getElementById('payment-form').reset();
+ document.querySelectorAll('.payment-option').forEach(option => {
+ option.classList.remove('selected');
+ });
+
+ document.querySelectorAll('.payment-details').forEach(details => {
+ details.classList.remove('active');
+ // Remove required attributes from all payment fields
+ details.querySelectorAll('[required]').forEach(field => {
+ field.removeAttribute('required');
+ });
+ });
+ }
+
+ function closeBankDetailsModal() {
+ const modal = document.getElementById('bankDetailsModal');
+ modal.style.display = 'none';
+ document.body.style.overflow = 'auto';
+
+ // Clear form and errors
+ document.getElementById('payment-form').reset();
+ document.querySelectorAll('.payment-option').forEach(option => {
+ option.classList.remove('selected');
+ });
+
+ document.querySelectorAll('.payment-details').forEach(details => {
+ details.classList.remove('active');
+ // Remove required attributes from all payment fields
+ details.querySelectorAll('[required]').forEach(field => {
+ field.removeAttribute('required');
+ });
+ });
+ }
+
function clearErrorMessages() {
document.getElementById('currentPasswordError').textContent = '';
document.getElementById('newPasswordError').textContent = '';
@@ -435,6 +587,8 @@
// Change password button
document.getElementById('changePasswordBtn').addEventListener('click', openPasswordModal);
+
+ document.getElementById('updateBankDetailsBtn').addEventListener('click', openBankDetailsModal);
// Password form submission
document.getElementById('passwordForm').addEventListener('submit', changePassword);
@@ -445,12 +599,19 @@
closePasswordModal();
}
});
+
+ document.getElementById('bankDetailsModal').addEventListener('click', function(e) {
+ if (e.target === this) {
+ closeBankDetailsModal();
+ }
+ });
// Close modal with escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closePasswordModal();
closeLogoutModal();
+ closeBankDetailsModal();
}
});
@@ -473,6 +634,625 @@
sidebar.classList.toggle('active');
});
});
-
+
+ // Function to select payment option
+ function selectPaymentOption(type) {
+ // Remove selected class from all options
+ document.querySelectorAll('.payment-option').forEach(option => {
+ option.classList.remove('selected');
+ });
+
+ document.querySelectorAll('.payment-details').forEach(details => {
+ details.classList.remove('active');
+ // Remove required attributes from all payment fields
+ details.querySelectorAll('[required]').forEach(field => {
+ field.removeAttribute('required');
+ });
+ });
+
+ // Add selected class to clicked option
+ event.currentTarget.classList.add('selected');
+
+ if (type === 'card') {
+ document.getElementById('card-details').classList.add('active');
+ // Add required attributes only to card fields
+ document.getElementById('card-number').setAttribute('required', 'true');
+ document.getElementById('expiry-date').setAttribute('required', 'true');
+ document.getElementById('security-code').setAttribute('required', 'true');
+ document.getElementById('card-zip').setAttribute('required', 'true');
+
+ } else if (type === 'bank') {
+ document.getElementById('bank-details').classList.add('active');
+ // Add required attributes only to bank fields
+ document.getElementById('bank-name').setAttribute('required', 'true');
+ document.getElementById('account-number').setAttribute('required', 'true');
+ document.getElementById('routing-number').setAttribute('required', 'true');
+ document.getElementById('account-type').setAttribute('required', 'true');
+ document.getElementById('account-holder-name').setAttribute('required', 'true');
+ }
+ }
+
+
+ // Bank Name validation
+ function validateBankName(input) {
+ const errorElement = document.getElementById('bank-name-error');
+ const value = input.value;
+
+ // Remove numbers and invalid special characters
+ const cleanValue = value.replace(/[^a-zA-Z\s\-'&.,()]/g, '');
+
+ if (value !== cleanValue) {
+ input.value = cleanValue;
+ }
+
+ // Check content
+ const contentCheck = value.replace(/[\s\-'&.,()]/g, '');
+ const hasOnlyNumbers = /^[0-9]+$/.test(contentCheck) && contentCheck.length > 0;
+ const hasOnlySpecialChars = /^[^a-zA-Z0-9]+$/.test(contentCheck) && contentCheck.length > 0;
+ const hasLetters = /[a-zA-Z]/.test(value);
+
+ if (value !== cleanValue && value.length > 0) {
+ errorElement.textContent = 'Bank name can only contain letters, spaces, and common punctuation';
+ errorElement.style.display = 'block';
+ input.classList.add('field-error');
+ return false;
+ } else if (hasOnlyNumbers) {
+ errorElement.textContent = 'Bank name cannot be only numbers';
+ errorElement.style.display = 'block';
+ input.classList.add('field-error');
+ return false;
+ } else if (hasOnlySpecialChars) {
+ errorElement.textContent = 'Bank name cannot be only special characters';
+ errorElement.style.display = 'block';
+ input.classList.add('field-error');
+ return false;
+ } else if (!hasLetters && value.trim().length > 0) {
+ errorElement.textContent = 'Bank name must include letters';
+ errorElement.style.display = 'block';
+ input.classList.add('field-error');
+ return false;
+ } else {
+ errorElement.style.display = 'none';
+ input.classList.remove('field-error');
+ return true;
+ }
+ }
+
+ function preventInvalidBankNameChars(event) {
+ const charCode = event.which ? event.which : event.keyCode;
+ const key = event.key;
+
+ if ((charCode >= 65 && charCode <= 90) ||
+ (charCode >= 97 && charCode <= 122) ||
+ charCode === 32 || charCode === 45 || charCode === 39 ||
+ charCode === 38 || charCode === 46 || charCode === 44 ||
+ charCode === 40 || charCode === 41 ||
+ charCode === 8 || charCode === 9 || charCode === 37 ||
+ charCode === 39 || charCode === 46 || charCode === 16 ||
+ charCode === 17 || charCode === 18 || charCode === 91 ||
+ /^[a-zA-Z\s\-'&.,()]$/.test(key)) {
+ return true;
+ }
+
+ event.preventDefault();
+ return false;
+ }
+
+ // Enhanced Account Number validation
+ function validateAccountNumber(input) {
+ const errorElement = document.getElementById('account-number-error');
+ const value = input.value.replace(/\s/g, '');
+
+ // Remove any non-digit characters
+ const cleanValue = value.replace(/\D/g, '');
+
+ if (value !== cleanValue) {
+ input.value = cleanValue;
+ }
+
+ // Validate account number
+ const isValid = validateAccountNumberStrict(cleanValue);
+
+ if (!isValid && cleanValue.length > 0) {
+ errorElement.textContent = getAccountNumberErrorMessage(cleanValue);
+ errorElement.style.display = 'block';
+ input.classList.add('field-error');
+ return false;
+ } else {
+ errorElement.style.display = 'none';
+ input.classList.remove('field-error');
+ return true;
+ }
+ }
+
+ function preventInvalidAccountNumberChars(event) {
+ const charCode = event.which ? event.which : event.keyCode;
+
+ if ((charCode >= 48 && charCode <= 57) ||
+ charCode === 8 || charCode === 9 || charCode === 37 ||
+ charCode === 39 || charCode === 46 || charCode === 16 ||
+ charCode === 17 || charCode === 18 || charCode === 91) {
+ return true;
+ }
+
+ event.preventDefault();
+ return false;
+ }
+
+ function validateAccountNumberStrict(accountNumber) {
+ if (!accountNumber || !/^\d+$/.test(accountNumber)) {
+ return false;
+ }
+
+ // Check length
+ if (accountNumber.length < 8 || accountNumber.length > 17) {
+ return false;
+ }
+
+ // Check for invalid patterns
+ if (isInvalidAccountNumberPattern(accountNumber)) {
+ return false;
+ }
+
+ // Simple checksum validation (basic example)
+ if (!isValidAccountNumberChecksum(accountNumber)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ function isInvalidAccountNumberPattern(accountNumber) {
+ const invalidPatterns = [
+ /^0+$/, // All zeros
+ /^1+$/, // All ones
+ /^2+$/, // All twos
+ /^3+$/, // All threes
+ /^4+$/, // All fours
+ /^5+$/, // All fives
+ /^6+$/, // All sixes
+ /^7+$/, // All sevens
+ /^8+$/, // All eights
+ /^9+$/, // All nines
+ /^12345678/, // Sequential
+ /^87654321/, // Reverse sequential
+ ];
+
+ return invalidPatterns.some(pattern => pattern.test(accountNumber));
+ }
+
+ function isValidAccountNumberChecksum(accountNumber) {
+ // Basic checksum validation - you might want to implement
+ // a more specific algorithm based on bank requirements
+ let sum = 0;
+ for (let i = 0; i < accountNumber.length; i++) {
+ sum += parseInt(accountNumber.charAt(i));
+ }
+
+ // Simple check: sum shouldn't be too low (e.g., all zeros)
+ return sum > 0;
+ }
+
+ function getAccountNumberErrorMessage(accountNumber) {
+ if (!accountNumber) {
+ return 'Account number is required';
+ }
+
+ if (!/^\d+$/.test(accountNumber)) {
+ return 'Account number must contain only numbers';
+ }
+
+ if (accountNumber.length < 8) {
+ return 'Account number must be at least 8 digits';
+ }
+
+ if (accountNumber.length > 17) {
+ return 'Account number cannot exceed 17 digits';
+ }
+
+ if (isInvalidAccountNumberPattern(accountNumber)) {
+ return 'Please enter a valid account number';
+ }
+
+ return 'Please enter a valid account number';
+ }
+
+ // Account Holder Name validation
+ function validateAccountHolderName(input) {
+ const errorElement = document.getElementById('account-holder-name-error');
+ const value = input.value;
+
+ // Remove numbers and special characters (keep only letters and spaces)
+ const cleanValue = value.replace(/[^a-zA-Z\s]/g, '');
+
+ if (value !== cleanValue) {
+ input.value = cleanValue;
+ }
+
+ // Check content
+ const hasOnlyNumbers = /^[0-9]+$/.test(value.replace(/\s/g, ''));
+ const hasOnlySpecialChars = /^[^a-zA-Z0-9]+$/.test(value.replace(/\s/g, ''));
+ const hasLetters = /[a-zA-Z]/.test(value);
+
+ if (value !== cleanValue && value.length > 0) {
+ errorElement.textContent = 'Account holder name can only contain letters and spaces';
+ errorElement.style.display = 'block';
+ input.classList.add('field-error');
+ return false;
+ } else if (hasOnlyNumbers) {
+ errorElement.textContent = 'Account holder name cannot contain only numbers';
+ errorElement.style.display = 'block';
+ input.classList.add('field-error');
+ return false;
+ } else if (hasOnlySpecialChars) {
+ errorElement.textContent = 'Account holder name cannot contain only special characters';
+ errorElement.style.display = 'block';
+ input.classList.add('field-error');
+ return false;
+ } else if (!hasLetters && value.trim().length > 0) {
+ errorElement.textContent = 'Account holder name must include letters';
+ errorElement.style.display = 'block';
+ input.classList.add('field-error');
+ return false;
+ } else {
+ errorElement.style.display = 'none';
+ input.classList.remove('field-error');
+ return true;
+ }
+ }
+
+ function preventInvalidAccountHolderChars(event) {
+ const charCode = event.which ? event.which : event.keyCode;
+ const key = event.key;
+
+ if ((charCode >= 65 && charCode <= 90) ||
+ (charCode >= 97 && charCode <= 122) ||
+ charCode === 32 ||
+ charCode === 8 || charCode === 9 || charCode === 37 ||
+ charCode === 39 || charCode === 46 || charCode === 16 ||
+ charCode === 17 || charCode === 18 || charCode === 91 ||
+ /^[a-zA-Z\s]$/.test(key)) {
+ return true;
+ }
+
+ event.preventDefault();
+ return false;
+ }
+
+
+ function preventNonNumericZip(event) {
+ const charCode = event.which ? event.which : event.keyCode;
+ const key = event.key;
+ const currentValue = event.target.value;
+
+ // Allow: numbers, hyphens (only in specific positions), and editing keys
+ if ((charCode >= 48 && charCode <= 57) || // 0-9
+ (charCode === 45 && currentValue.length === 5 && !currentValue.includes('-')) || // hyphen only after 5 digits
+ charCode === 8 || // backspace
+ charCode === 9 || // tab
+ charCode === 37 || // left arrow
+ charCode === 39 || // right arrow
+ charCode === 46 || // delete
+ charCode === 16 || // shift
+ charCode === 17 || // ctrl
+ charCode === 18 || // alt
+ charCode === 91) { // cmd (Mac)
+ return true;
+ }
+
+ // Prevent all other characters including letters and special characters
+ event.preventDefault();
+ return false;
+ }
+
+ // Function to validate ZIP code in real-time
+ function validateZipCode(input) {
+ let errorElement;
+
+ // Determine which error element to use based on input ID
+ if (input.id === 'billing-zip') {
+ errorElement = document.getElementById('billing-zip-error');
+ } else if (input.id === 'card-zip') {
+ errorElement = document.getElementById('card-zip-error');
+ } else {
+ errorElement = document.getElementById('zip-error');
+ }
+
+ const value = input.value;
+
+ // Remove any non-numeric characters except hyphens
+ const cleanValue = value.replace(/[^0-9\-]/g, '');
+
+ // If invalid characters were removed, update the input value
+ if (value !== cleanValue) {
+ input.value = cleanValue;
+ }
+
+ // Format ZIP code as user types (add hyphen after 5 digits)
+ if (cleanValue.length === 5 && !cleanValue.includes('-')) {
+ input.value = cleanValue;
+ } else if (cleanValue.length > 5 && !cleanValue.includes('-')) {
+ input.value = cleanValue.substring(0, 5) + '' + cleanValue.substring(5, 9);
+ }
+
+
+ if (input.value.length < 4) {
+ errorElement.style.display = 'block';
+ input.classList.add('field-error');
+ return false;
+ } else {
+ errorElement.style.display = 'none';
+ input.classList.remove('field-error');
+ return true;
+ }
+ }
+
+
+ // Function to validate CVV in real-time
+ function validateCVVVV(input) {
+ const errorElement = document.getElementById('security-code-error');
+ const value = input.value;
+
+ // Remove any non-digit characters
+ const cleanValue = value.replace(/\D/g, '');
+
+ // If non-digits were removed, update the input value
+ if (value !== cleanValue) {
+ input.value = cleanValue;
+ }
+
+ // Get card type to determine expected CVV length
+ const cardNumber = document.getElementById('card-number').value;
+ const cardType = detectCardType(cardNumber);
+
+ // Validate CVV format and content
+ const isValid = validateCVVStrict(cleanValue, cardType);
+
+ if (!isValid && cleanValue.length > 0) {
+ errorElement.textContent = getCVVErrorMessage(cleanValue, cardType);
+ errorElement.style.display = 'block';
+ input.classList.add('field-error');
+ return false;
+ } else {
+ errorElement.style.display = 'none';
+ input.classList.remove('field-error');
+ return true;
+ }
+ }
+
+ // Card type detection
+ function detectCardType(cardNumber) {
+ // Remove spaces and dashes
+ const cleanNumber = cardNumber.replace(/[\s-]/g, '');
+
+ const cardPatterns = {
+ visa: /^4[0-9]{12}(?:[0-9]{3})?$/,
+ mastercard: /^5[1-5][0-9]{14}$/,
+ amex: /^3[47][0-9]{13}$/,
+ discover: /^6(?:011|5[0-9]{2})[0-9]{12}$/,
+ diners: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
+ jcb: /^(?:2131|1800|35\d{3})\d{11}$/
+ };
+
+ for (const [type, pattern] of Object.entries(cardPatterns)) {
+ if (pattern.test(cleanNumber)) {
+ return type;
+ }
+ }
+ return 'unknown';
+ }
+
+ // Function to prevent invalid character input in CVV field
+ function preventInvalidCVVChars(event) {
+ const charCode = event.which ? event.which : event.keyCode;
+ const key = event.key;
+
+ // Allow only digits and common editing keys
+ if ((charCode >= 48 && charCode <= 57) || // 0-9
+ charCode === 8 || // backspace
+ charCode === 9 || // tab
+ charCode === 37 || // left arrow
+ charCode === 39 || // right arrow
+ charCode === 46 || // delete
+ charCode === 16 || // shift
+ charCode === 17 || // ctrl
+ charCode === 18 || // alt
+ charCode === 91) { // cmd (Mac)
+ return true;
+ }
+
+ // Prevent all non-digit characters
+ event.preventDefault();
+ return false;
+ }
+
+ // Enhanced CVV validation function
+ function validateCVVStrict(cvv, cardType) {
+ if (!cvv || !/^\d+$/.test(cvv)) {
+ return false;
+ }
+
+ // Check for invalid patterns
+ if (isInvalidCVVPattern(cvv)) {
+ return false;
+ }
+
+ const cvvLengths = {
+ visa: 3,
+ mastercard: 3,
+ amex: 4,
+ discover: 3,
+ diners: 3,
+ jcb: 3
+ };
+
+ const expectedLength = cvvLengths[cardType] || 3;
+
+ // Check length
+ if (cvv.length !== expectedLength) {
+ return false;
+ }
+
+ return true;
+ }
+
+ // Function to check for invalid CVV patterns
+ function isInvalidCVVPattern(cvv) {
+ const invalidPatterns = [
+ /^0+$/, // All zeros: 000, 0000
+ /^1+$/, // All ones: 111, 1111
+ /^2+$/, // All twos: 222, 2222
+ /^3+$/, // All threes: 333, 3333
+ /^4+$/, // All fours: 444, 4444
+ /^5+$/, // All fives: 555, 5555
+ /^6+$/, // All sixes: 666, 6666
+ /^7+$/, // All sevens: 777, 7777
+ /^8+$/, // All eights: 888, 8888
+ /^9+$/, // All nines: 999, 9999
+ ];
+
+ return invalidPatterns.some(pattern => pattern.test(cvv));
+ }
+
+ // Function to get appropriate CVV error message
+ function getCVVErrorMessage(cvv, cardType) {
+ if (!cvv) {
+ return 'Security code is required';
+ }
+
+ if (!/^\d+$/.test(cvv)) {
+ return 'Security code must contain only numbers';
+ }
+
+ if (isInvalidCVVPattern(cvv)) {
+ return 'Please enter a valid security code';
+ }
+
+ const cvvLengths = {
+ visa: 3,
+ mastercard: 3,
+ amex: 4,
+ discover: 3,
+ diners: 3,
+ jcb: 3
+ };
+
+ const expectedLength = cvvLengths[cardType] || 3;
+
+ if (cvv.length !== expectedLength) {
+ if (cardType === 'amex') {
+ return 'American Express cards require a 4-digit security code';
+ } else {
+ return `Security code must be ${expectedLength} digits`;
+ }
+ }
+
+ return 'Please enter a valid security code';
+ }
+
+ document.addEventListener('DOMContentLoaded', function() {
+ // Real-time card number formatting and validation
+ const cardNumberInput = document.getElementById('card-number');
+ if (cardNumberInput) {
+ cardNumberInput.addEventListener('input', function(e) {
+ const cursorPosition = e.target.selectionStart;
+ const originalLength = e.target.value.length;
+ // Format card number with spaces
+ let value = e.target.value.replace(/\s/g, '');
+ let formattedValue = '';
+
+ for (let i = 0; i < value.length; i++) {
+ if (i > 0 && i % 4 === 0) {
+ formattedValue += ' ';
+ }
+ formattedValue += value[i];
+ }
+
+ e.target.value = formattedValue;
+
+ let newCursorPosition = cursorPosition;
+
+ if (formattedValue.length > originalLength) {
+ const addedChars = formattedValue.length - originalLength;
+
+ // Count how many spaces were added before the cursor position
+ let spacesAddedBeforeCursor = 0;
+ for (let i = 0; i < cursorPosition && i < formattedValue.length; i++) {
+ if (formattedValue[i] === ' ' && (i < cursorPosition ||
+ (i === cursorPosition && formattedValue[i] === ' '))) {
+ spacesAddedBeforeCursor++;
+ }
+ }
+
+ newCursorPosition = cursorPosition + spacesAddedBeforeCursor;
+ } else if (formattedValue.length < originalLength) {
+ const removedChars = originalLength - formattedValue.length;
+
+ // Count how many spaces were removed before the cursor position
+ let spacesRemovedBeforeCursor = 0;
+ const oldValue = e.target.getAttribute('data-old-value') || '';
+ for (let i = 0; i < cursorPosition && i < oldValue.length; i++) {
+ if (oldValue[i] === ' ' && i < cursorPosition) {
+ spacesRemovedBeforeCursor++;
+ }
+ }
+
+ newCursorPosition = Math.max(0, cursorPosition - spacesRemovedBeforeCursor);
+ }
+
+ e.target.setAttribute('data-old-value', formattedValue);
+ e.target.setSelectionRange(newCursorPosition, newCursorPosition);
+
+ // Real-time card type detection
+ const cardType = detectCardType(value);
+ if (cardType !== 'unknown') {
+ // You can add visual feedback for card type here
+ console.log('Card type:', cardType);
+ }
+ });
+
+ cardNumberInput.addEventListener('keydown', function(e) {
+ // Allow: backspace, delete, tab, escape, enter, arrows, home, end
+ if ([8, 9, 13, 27, 37, 38, 39, 40, 46].includes(e.keyCode) ||
+ // Allow: Ctrl+A, Ctrl+C, Ctrl+V, Ctrl+X
+ (e.keyCode === 65 && e.ctrlKey === true) ||
+ (e.keyCode === 67 && e.ctrlKey === true) ||
+ (e.keyCode === 86 && e.ctrlKey === true) ||
+ (e.keyCode === 88 && e.ctrlKey === true) ||
+ // Allow: numbers and numpad numbers
+ (e.keyCode >= 48 && e.keyCode <= 57) ||
+ (e.keyCode >= 96 && e.keyCode <= 105)) {
+ return;
+ }
+
+ // Prevent all other keys
+ e.preventDefault();
+ });
+ }
+
+ // Real-time expiry date formatting
+ const expiryInput = document.getElementById('expiry-date');
+ if (expiryInput) {
+ expiryInput.addEventListener('input', function(e) {
+ let value = e.target.value.replace(/\D/g, '');
+ if (value.length >= 2) {
+ value = value.substring(0, 2) + '/' + value.substring(2, 4);
+ }
+ e.target.value = value;
+ });
+ }
+
+ // Real-time CVV validation
+ const cvvInput = document.getElementById('security-code');
+ if (cvvInput) {
+ cvvInput.addEventListener('input', function(e) {
+ e.target.value = e.target.value.replace(/\D/g, '').substring(0, 4);
+ });
+ }
+
+
+ });
+
+