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/js/components/white-label-cfd-broker/Validation.js
import {handle} from "./handle";

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

    const arrayErrors = [];
    const errors = [];

    const validation = (item) => {
        switch (item.id) {
            case 'first_name':
            case 'first_name-popup':
                if (item.value.trim() === '') {
                    errors.push(true);
                    arrayErrors[item.id] = "Required";
                } else {
                    errors.push(false);
                    arrayErrors[item.id] = '';
                }
                break;
            case 'terms_agree':
            case 'terms_agree-popup':
                if (!item.checked) {
                    errors.push(true);
                    arrayErrors[item.id] = "Required";
                } else {
                    errors.push(false);
                    arrayErrors[item.id] = '';
                }
                break;
            case 'range':
            case 'range-popup':
                if (!Number(item.value)) {
                    errors.push(true);
                    arrayErrors[item.id] = "Required";
                } else {
                    errors.push(false);
                    arrayErrors[item.id] = '';
                }
                break;
            case 'phone':
            case 'phone-popup':
                let regExp = /^[\d\+][\d\(\)\ -]{4,14}\d$/;
                const phone = item.value.trim();

                if (phone === '') {
                    errors.push(true);
                    arrayErrors[item.id] = "Required";
                } else {
                    if (!regExp.test(phone) || phone.length < 10) {
                        errors.push(true);
                        arrayErrors[item.id] = "Not valid phone";
                    } else {
                        errors.push(false);
                        arrayErrors[item.id] = '';
                    }
                }
                break;
            case 'email':
            case 'email-popup':
                if (item.value.trim() === '') {
                    errors.push(true);
                    arrayErrors[item.id] = "Required";
                } 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] = '';
                    } else {
                        errors.push(true);
                        arrayErrors[item.id] = "Not valid email";
                    }
                }
                break;
        }
        handle(arrayErrors);
    };

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


    return errors.includes(true);
};

export default Validate;