<commit_before>import { isNumber } from 'lodash';
import { robotToHuman } from '../../robotToHumanFilter/robotToHuman.filter';

import type { IValidator } from './validation';

const THIS_FIELD = 'This field';

const emailValue = (message?: string): IValidator => {
  return function emailValue(val: string, label = THIS_FIELD) {
    message = message || `${label} is not a valid email address.`;
    return val && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(val) && message;
  };
};

const isRequired = (message?: string): IValidator => {
  return function isRequired(val: any, label = THIS_FIELD) {
    message = message || `${label} is required.`;
    return (val === undefined || val === null || val === '') && message;
  };
};
<commit_msg>Updating email validation to allow for longer domains per issue-6636 (#9841)<commit_after>import { isNumber } from 'lodash';
import { robotToHuman } from '../../robotToHumanFilter/robotToHuman.filter';

import type { IValidator } from './validation';

const THIS_FIELD = 'This field';
// RCF 5322 Email Validation Regex taken from https://emailregex.com/
const VALID_EMAIL_REGEX = new RegExp(
  '^(([^<>()\\[\\]\\\\.,;:\\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,}))$',
);

const emailValue = (message?: string): IValidator => {
  return function emailValue(val: string, label = THIS_FIELD) {
    message = message || `${label} is not a valid email address.`;
    return val && !VALID_EMAIL_REGEX.test(val) && message;
  };
};

const isRequired = (message?: string): IValidator => {
  return function isRequired(val: any, label = THIS_FIELD) {
    message = message || `${label} is required.`;
    return (val === undefined || val === null || val === '') && message;
  };
};

{'fraction_non_alphanumeric': 0.23228995057660626, 'fraction_numerical': 0.020318506315211423, 'mean_word_length': 3.807387862796834, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '979682', 'n_tokens_mistral': 642, 'n_tokens_neox': 621, 'n_words': 151}