HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/propbase/propbase_website/shared/utils/constants.ts
export const alphaCheck = (value: string): boolean => !/^[\p{Letter}\s\-.']+$/u.test(value);

export const validateEmail = (value: string): boolean =>
  !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i.test(value);

export const validateNumber = (value: string): boolean =>
  !/^[+-]?((\.\d+)|(\d+(\.\d+)?)|(\d+\.))$/i.test(value);

export const isImageFile = (file: File): boolean => /^image\/(jpeg|jpg|png)$/.test(file.type);

export const validatePhone = (value: string): boolean => {
  const phoneRegex =
    /^\s*(?:\+(\d{1,3}))?[-. (]*\d{1,4}[-. )]*\d{1,4}[-. ]*\d{1,4}[-. ]*\d{1,9}(?: *x(\d+))?\s*$/;
  return !phoneRegex.test(value);
};

const hasMinimumLength = (value: string): boolean => value?.length >= 8;

const hasUppercase = (value: string): boolean => /[A-Z]/.test(value);

const hasLowercase = (value: string): boolean => /[a-z]/.test(value);

const hasDigit = (value: string): boolean => /[0-9]/.test(value);

const hasSpecialCharacter = (value: string): boolean => /[_/{}~$&+,:;=?@#|'<>.^*()%!-]/.test(value);

const hasSpacesInBetween = (value: string): boolean => /\s/.test(value) && !/^\s|\s$/.test(value);

export const validatePassword = (value: string): string | null => {
  if (!hasMinimumLength(value)) {
    return 'Password must be at least 8 characters long';
  }
  if (!hasUppercase(value)) {
    return 'Password must contain at least one uppercase letter';
  }
  if (!hasLowercase(value)) {
    return 'Password must contain at least one lowercase letter';
  }
  if (!hasDigit(value)) {
    return 'Password must contain at least one number';
  }
  if (!hasSpecialCharacter(value)) {
    return 'Password must contain at least one special character';
  }
  if (hasSpacesInBetween(value)) {
    return "Password can't contain spaces";
  }
  return null;
};