// Mobile Number Validation
function isNumberKey(evt) {
    const charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
}

function validateMobile(mobile) {
    const mobileError = document.getElementById('mobileError');
    const mobileInput = document.getElementById('mobile_no');
    
    // Prevent entering more than 10 digits
    if (mobile.length > 10) {
        mobileInput.value = mobile.slice(0, 10);
        return false;
    }
    
    if (mobile.length !== 10) {
        mobileError.textContent = 'Mobile number must be exactly 10 digits';
        return false;
    } else {
        mobileError.textContent = '';
        return true;
    }
}

// Email Validation
function validateEmail(email) {
    const emailError = document.getElementById('emailError');
    const emailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
    if (!emailRegex.test(email)) {
        emailError.textContent = 'Please enter a valid email address';
        return false;
    } else {
        emailError.textContent = '';
        return true;
    }
}

// PAN Validation
function validatePAN(pan) {
    const panError = document.getElementById('panError');
    const panRegex = /^[A-Z]{5}[0-9]{4}[A-Z]{1}$/;
    if (!panRegex.test(pan)) {
        panError.textContent = 'Please enter a valid PAN (e.g., ABCDE1234F)';
        return false;
    } else {
        panError.textContent = '';
        return true;
    }
}

// Form Validation
function validateForm() {
    const mobileValid = validateMobile(document.getElementById('mobile_no').value);
    const emailValid = validateEmail(document.getElementById('email_id').value);
    const panValid = validatePAN(document.getElementById('pan_no').value);
    
    return mobileValid && emailValid && panValid;
}



