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.com/src/routes/api/popup/Validation.ts
import type { IRequest } from '$type/form';
import { t } from '$lib/translations';

const Validation = (value: IRequest) => {
  const error: { [name: string]: string } = {};

  if (Object.values(value).length) {
    if (value['email'] === undefined || value['email'] === '') {
      error['email'] = `*${t.get('Required field')}`;
    } else {
      if (
        !value['email'].match(
          /^(([^<>()[\]\\.,;:\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,}))$/
        )
      ) {
        error['email'] = `*${t.get('Not valid email')}`;
      }
    }
    if (value['first_name'] === undefined || value['first_name'] === '') {
      error['first_name'] = `*${t.get('Required field')}`;
    }
    if (value['phone'] === undefined || value['phone'] === '') {
      error['phone'] = `*${t.get('Required field')}`;
    } else {
      if (!value['phone'].match(/^[\d\+][\d\(\)\ -]{4,14}\d$/)) {
        error['phone'] = `*${t.get('Not valid phone number')}`;
      }
    }
    if (value['agreement'] === undefined || !value['agreement']) {
      error['agreement'] = `*${t.get('Required field')}`;
    }
  } else {
    error['email'] = `*${t.get('Required field')}`;
    error['first_name'] = `*${t.get('Required field')}`;
    error['phone'] = `*${t.get('Required field')}`;
    error['terms_agree'] = `*${t.get('Required field')}`;
  }

  return error;
};

export default Validation;