Fixed issues and bugs
This commit is contained in:
parent
dc085787a3
commit
dea2a2985e
|
|
@ -495,6 +495,15 @@ async function validateStep(step) {
|
|||
if (!validateEmail(email) && !companyName) {
|
||||
isValid = false;
|
||||
showError('Both Fields are Required', null, step);
|
||||
let requiredFields1 = form.querySelectorAll('[required]');
|
||||
requiredFields1.forEach(field => {
|
||||
if (!field.value.trim()) {
|
||||
isValid = false;
|
||||
field.classList.add('field-error');
|
||||
} else if (field.id !== 'email') {
|
||||
field.classList.remove('field-error');
|
||||
}
|
||||
});
|
||||
return isValid;
|
||||
}
|
||||
if (!validateEmail(email)) {
|
||||
|
|
@ -856,6 +865,8 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
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 = '';
|
||||
|
|
@ -869,6 +880,39 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
|
||||
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') {
|
||||
|
|
@ -876,6 +920,24 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||
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
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@
|
|||
// Age validation
|
||||
const age = document.getElementById('age').value;
|
||||
if (age && (age < 18 || age > 100)) {
|
||||
showError('You must be 18 years or older to register', 'dob', step);
|
||||
showError('You age must be 18 years or older to register', 'dob', step);
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
|
|
@ -741,10 +741,12 @@
|
|||
|
||||
// Validate age
|
||||
if (age < 18) {
|
||||
alert('You must be 18 years or older to register');
|
||||
// alert('You must be 18 years or older to register');
|
||||
showError('You Age must be 18 years or older to register', 'dob',);
|
||||
ageInput.style.border = '1px solid #ef4444';
|
||||
} else if (age > 100) {
|
||||
alert('Please enter a valid age');
|
||||
// alert('Please enter a valid age');
|
||||
showError('Please enter a valid age', 'dob');
|
||||
ageInput.style.border = '1px solid #ef4444';
|
||||
} else {
|
||||
ageInput.style.border = '';
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ class PasswordResetService {
|
|||
if (!user) {
|
||||
logger.info(`Password reset requested for non-existent ${userType}: ${email}`);
|
||||
return {
|
||||
success: true,
|
||||
message: "If the email exists, a reset link has been sent"
|
||||
success: false,
|
||||
message: "Email not recognized. Please sign up to continue."
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -127,6 +127,11 @@
|
|||
</div>
|
||||
|
||||
<script>
|
||||
function validateEmail(email) {
|
||||
const emailRegex = /^[a-zA-Z0-9](?:[a-zA-Z0-9]*[._-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9]*[-]?[a-zA-Z0-9]+)*\.[a-zA-Z]{2,}$/;
|
||||
return emailRegex.test(email);
|
||||
}
|
||||
|
||||
(function () {
|
||||
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
const logo = document.getElementById("logo");
|
||||
|
|
@ -154,8 +159,8 @@
|
|||
e.preventDefault();
|
||||
|
||||
const email = emailInput.value.trim();
|
||||
if (!email) {
|
||||
alert("Please enter your email address.");
|
||||
if (!email || !validateEmail(email)) {
|
||||
alert("Please enter valid email address.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -174,8 +179,13 @@
|
|||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
if(response.success) {
|
||||
if(confirm('Please Check your mail inbox for password reset link')) {
|
||||
window.location.href = "/client/login"; // Redirect to reset password page
|
||||
// console.log(response)
|
||||
}
|
||||
} else {
|
||||
alert(data.message || "Failed to send reset link.");
|
||||
}
|
||||
} else {
|
||||
alert("❌ " + (data.message || "Failed to send reset link."));
|
||||
|
|
|
|||
Loading…
Reference in New Issue