HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //var/www/quadcode-site/src/utils/ValidateInput.js
import { handle } from "./ErrorHandler";
import { langArr } from "../js/components/lp/saas2/LangArray";

const ValidateInput = (inputs) => {
    if (!inputs) return;

    const arrayErrors = [];
    const errors = [];
    let hash = localStorage.getItem('form__lang');

    const validation = (item) => {
        const error = document.getElementById(item.id + '-error');
        switch (item.id) {
            case 'first_name':
                if (item.value.trim() === '') {
                    errors.push(true);
                    arrayErrors[item.id] = langArr['Required'][hash];
                } else {
                    errors.push(false);
                    arrayErrors[item.id] = '';
                }
                break;
            case 'region':
            case 'options':
            case 'range':
                if (window.innerWidth >= 768) {
                    if (item.value.trim() === '') {
                        errors.push(true);
                        arrayErrors[item.id] = langArr['Required'][hash];
                    } else {
                        errors.push(false);
                        arrayErrors[item.id] = '';
                    }
                }
                break;
            case 'saas-phone':
                let regExp = /^[\d\+][\d\(\)\ -]{4,14}\d$/;
                const phone = item.value.trim();

                if (phone === '') {
                    errors.push(true);
                    arrayErrors[item.id] = langArr['Required'][hash];
                } else {
                    if (!regExp.test(phone) || phone.length < 10) {
                        errors.push(true);
                        error.dataset.lang = 'lng-Numeric';
                        arrayErrors[item.id] = langArr['Numeric'][hash];
                    } else {
                        errors.push(false);
                        arrayErrors[item.id] = '';
                        error.dataset.lang = 'lng-Required';
                    }
                }
                break;
            case 'email':
                if (item.value.trim() === '') {
                    errors.push(true);
                    arrayErrors[item.id] = langArr['Required'][hash];
                } else {
                    const regular = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

                    if (regular.test(item.value.trim())) {
                        errors.push(false);
                        arrayErrors[item.id] = '';
                        error.dataset.lang = 'lng-Required'
                    } else {
                        errors.push(true);
                        error.dataset.lang = 'lng-EmailInvalid';
                        arrayErrors[item.id] = langArr['EmailInvalid'][hash];
                    }
                }
                break;
        }
        handle(arrayErrors);
    };

    if (inputs.length > 1) {
        inputs.forEach((item) => {
            validation(item);
        });
    } else {
        validation(inputs);
    }


    return errors.includes(true);
};

export default ValidateInput;