1 import isValidDomain from 'is-valid-domain';
3 /* eslint-disable no-useless-escape */
4 export const REGEX_URL =
5 /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/;
6 export const REGEX_HEX_COLOR = /^#([a-f0-9]{3,4}|[a-f0-9]{4}(?:[a-f0-9]{2}){1,2})\b$/i;
7 export const REGEX_NUMBER = /^\d+$/;
8 export const REGEX_PUNYCODE = /^(http|https):\/\/xn--/;
9 export const REGEX_USERNAME = /^[A-Za-z0-9]+(?:[_.-][A-Za-z0-9]+)*$/;
10 export const REGEX_USERNAME_START = /^[A-Za-z0-9]/;
11 export const REGEX_USERNAME_END = /[A-Za-z0-9]$/;
13 export const isEmpty = (value = '') => !value.length;
14 export const maxLength = (value = '', limit = 0) => value.length <= limit;
15 export const minLength = (value = '', limit = 0) => value.length >= limit;
16 export const isURL = (value = '') => {
17 if (/\s/.test(value)) {
18 // A URL should contain no spaces
19 // (doing this check separately as URL_REGEX is not checking it)
22 return REGEX_URL.test(value);
24 export const isDomain = isValidDomain;
25 export const isHexColor = (value = '') => REGEX_HEX_COLOR.test(value);
26 export const isNumber = (value = '') => REGEX_NUMBER.test(value);
27 export const isBase64Image = (value = '') => value.startsWith('data:image') && value.includes(';base64');
28 export const isPunycode = (value = '') => REGEX_PUNYCODE.test(value);