Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const form = document.getElementById('registrationForm');
+ const successMessage = document.getElementById('successMessage');
+
+ const personalEmails = [
+ 'qq.com',
+ '163.com',
+ 'gmail.com',
+ 'yahoo.com',
+ 'hotmail.com',
+ 'outlook.com'
+ ];
+
+ const validateName = (name) => {
+ return name.trim().length >= 2;
+ };
+
+ const validatePhone = (phone) => {
+ const phoneRegex = /^\+?[\d\s-()]{10,}$/;
+ return phoneRegex.test(phone);
+ };
+
+ const validateEmail = (email) => {
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
+ if (!emailRegex.test(email)) return false;
+
+ const domain = email.split('@')[1].toLowerCase();
+ return !personalEmails.includes(domain);
+ };
+
+ const showError = (elementId, message) => {
+ const errorElement = document.getElementById(elementId);
+ errorElement.textContent = message;
+ };
+
+ const clearErrors = () => {
+ const errorElements = document.querySelectorAll('.error');
+ errorElements.forEach(element => element.textContent = '');
+ };
+
+ form.addEventListener('submit', (e) => {
+ e.preventDefault();
+ clearErrors();
+
+ const name = form.name.value;
+ const phone = form.phone.value;
+ const email = form.email.value;
+
+ let isValid = true;
+
+ if (!validateName(name)) {
+ showError('nameError', 'Please enter a valid name (minimum 2 characters)');
+ isValid = false;
+ }
+
+ if (!validatePhone(phone)) {
+ showError('phoneError', 'Please enter a valid phone number');
+ isValid = false;
+ }
+
+ if (!validateEmail(email)) {
+ showError('emailError', 'Please enter a valid company email address');
+ isValid = false;
+ }
+
+ if (isValid) {
+ form.reset();
+ form.style.display = 'none';
+ successMessage.classList.remove('hidden');
+
+ // Reset form after 3 seconds
+ setTimeout(() => {
+ form.style.display = 'block';
+ successMessage.classList.add('hidden');
+ }, 3000);
+ }
+ });
+
+ // Real-time validation
+ form.querySelectorAll('input').forEach(input => {
+ input.addEventListener('blur', () => {
+ clearErrors();
+ switch(input.name) {
+ case 'name':
+ if (!validateName(input.value)) {
+ showError('nameError', 'Please enter a valid name (minimum 2 characters)');
+ }
+ break;
+ case 'phone':
+ if (!validatePhone(input.value)) {
+ showError('phoneError', 'Please enter a valid phone number');
+ }
+ break;
+ case 'email':
+ if (!validateEmail(input.value)) {
+ showError('emailError', 'Please enter a valid company email address');
+ }
+ break;
+ }
+ });
+ });
+ });