Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const form = document.getElementById('registrationForm');
+ const nameInput = document.getElementById('name');
+ const phoneInput = document.getElementById('phone');
+ const emailInput = document.getElementById('email');
+
+ const nameError = document.getElementById('nameError');
+ const phoneError = document.getElementById('phoneError');
+ const emailError = document.getElementById('emailError');
+
+ const personalEmailDomains = [
+ 'qq.com',
+ '163.com',
+ 'gmail.com',
+ 'yahoo.com',
+ 'hotmail.com',
+ 'outlook.com'
+ ];
+
+ const validatePhone = (phone) => {
+ // Chinese phone number format validation
+ const phoneRegex = /^(\+86\s?)?1[3-9]\d{9}$/;
+ return phoneRegex.test(phone.replace(/[\s-]/g, ''));
+ };
+
+ const validateEmail = (email) => {
+ const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
+ if (!emailRegex.test(email)) return false;
+
+ const domain = email.split('@')[1].toLowerCase();
+ return !personalEmailDomains.includes(domain);
+ };
+
+ const showError = (element, errorText) => {
+ element.textContent = errorText;
+ element.parentElement.querySelector('input').classList.add('error');
+ };
+
+ const clearError = (element) => {
+ element.textContent = '';
+ element.parentElement.querySelector('input').classList.remove('error');
+ };
+
+ form.addEventListener('submit', (e) => {
+ e.preventDefault();
+ let isValid = true;
+
+ // Clear previous errors
+ [nameError, phoneError, emailError].forEach(clearError);
+
+ // Validate name
+ if (!nameInput.value.trim()) {
+ showError(nameError, 'Please enter your name');
+ isValid = false;
+ }
+
+ // Validate phone
+ if (!validatePhone(phoneInput.value)) {
+ showError(phoneError, 'Please enter a valid Chinese phone number');
+ isValid = false;
+ }
+
+ // Validate email
+ if (!validateEmail(emailInput.value)) {
+ showError(emailError, 'Please enter a valid business email address');
+ isValid = false;
+ }
+
+ if (isValid) {
+ // Form is valid, you can submit the data here
+ alert('Registration successful!');
+ form.reset();
+ }
+ });
+
+ // Real-time validation
+ [nameInput, phoneInput, emailInput].forEach(input => {
+ input.addEventListener('input', () => {
+ clearError(document.getElementById(`${input.id}Error`));
+ });
+ });
+ });