Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function validate() {
- let submitBtn = document.getElementById('submit');
- let isCompany = false;
- submitBtn.addEventListener('click', (e) => {
- e.preventDefault();
- let username = document.getElementById('username');
- let email = document.getElementById('email');
- let password = document.getElementById('password');
- let confirmPassword = document.getElementById('confirm-password');
- let companyNumber = document.getElementById('companyNumber');
- let validDiv = document.getElementById('valid');
- let allIsValid = true;
- if (username.value.length >= 3 && username.value.length <= 20 && /^[A-Za-z0-9]+$/.test(username.value)) {
- username.style.borderColor = '';
- } else {
- username.style.borderColor = 'red';
- allIsValid = false;
- }
- if (/^[^@.]+@[^@]*\.[^@]*$/.test(email.value)) {
- email.style.borderColor = '';
- } else {
- email.style.borderColor = 'red';
- allIsValid = false;
- }
- if (/^\w{5,15}$/.test(password.value)) {
- password.style.borderColor = '';
- } else {
- password.style.borderColor = 'red';
- allIsValid = false;
- }
- if (/^\w{5,15}$/.test(confirmPassword.value) && confirmPassword.value === password.value) {
- confirmPassword.style.borderColor = '';
- } else {
- confirmPassword.style.borderColor = 'red';
- allIsValid = false;
- }
- if (isCompany) {
- if (Number(companyNumber.value) >= 1000 && Number(companyNumber.value) <= 9999) {
- companyNumber.style.borderColor = '';
- } else {
- companyNumber.style.borderColor = 'red';
- allIsValid = false;
- }
- }
- if (allIsValid) {
- validDiv.style.display = 'block';
- } else {
- validDiv.style.display = 'none';
- }
- });
- let companyInfo = document.getElementById('companyInfo');
- let companyCheckBox = document.getElementById('company');
- companyCheckBox.addEventListener('change', (e) => {
- if (e.target.checked) {
- companyInfo.style.display = 'block';
- isCompany = true;
- } else {
- companyInfo.style.display = 'none';
- isCompany = false;
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement