Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | 4x 125x 125x 125x 125x 2x 2x 125x 3x 3x 3x 3x 6x 6x 6x 2x 4x 2x 2x 2x 4x 2x 2x 2x 1x 1x 4x 2x 5x 5x 5x | import passwordcheck from './passwordcheck';
import { getAdministrativeArea, COUNTRY_CODES } from './iso3166codes';
import { emailTypoList, trustedEmailDomains } from './emailLists';
import { ageGate } from './agegate';
// see: https://github.com/ThirstieAdmin/archived-repos/tree/master/thirstie-templates/react-cookbook/src/utils
// Validator must return true or false
const Validators = {
email: (value, options = null) => {
const checkTypeoList = (options && options.checkTypeos) ? options.checkTypeos : false;
const emailRegex = /^(?![.!#$%&'*+/=?^_`{|}~-])(?!.*\.{2})[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]{1,63}[a-zA-Z0-9]@[a-zA-Z0-9][a-zA-Z0-9.-]{0,250}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/;
let isValid = emailRegex.test(value);
if (isValid && checkTypeoList) {
const emailDomain = value.split('@')[1].toLowerCase();
isValid = !emailTypoList.includes(emailDomain);
}
return isValid;
},
emailHasTrustedDomain: (value, options = null) => {
const emailParts = value && value.toLowerCase().split('@');
Eif (emailParts && emailParts.length === 2) {
const emailDomain = emailParts[1];
return trustedEmailDomains.includes(emailDomain);
}
return false;
},
phoneNumber: (value, options = null) => {
const phoneRegex = /^((\+1|1)?( |-)?)?(\([2-9][0-9]{2}\)|[2-9][0-9]{2})( |-)?([2-9][0-9]{2}( |-)?[0-9]{4})$/;
if (value) {
const testValue = String(value).replace(/[^0-9]/g, '');
return phoneRegex.test(testValue);
}
return false;
},
postalCode: (value, options = null) => {
const country = (options && options.countryCode) ? options.countryCode.toLowerCase() : 'en-us';
const regex = {
'en-us': /^\d{5}$/,
'en-ca': /^[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d$/
}[country];
if (regex) {
return regex.test(value);
}
return false;
},
stateProvinceCode: (value, options = null) => {
const countryCode = (options && options.countryCode) ? options.countryCode.toLowerCase() : 'en-us';
const check = getAdministrativeArea(value.toUpperCase(), countryCode);
if (!check) {
return false;
} else {
return true;
}
},
currencyValue: (value, options = null) => {
const countryCode = (options && options.countryCode) ? options.countryCode.toLowerCase() : 'en-us';
const countryValues = COUNTRY_CODES[countryCode];
const currencySymbols = countryValues.currency;
const checkValue = currencySymbols.reduce((acc, val) => acc.replace(val, ''), value).replace(' ', '');
const regx0 = /[^.^\d]+/;
const regx = /\d+\.+\d+/;
if (!regx0.test(checkValue)) {
return regx.test(checkValue);
} else {
return false;
}
}
};
const Checkers = {
passwordStrength: (value, options = null) => { return passwordcheck(value); },
emailCheck: (value, options = null) => {
const isValid = Validators.email(value, { checkTypeos: true });
const isTrusted = Validators.emailHasTrustedDomain(value);
return { isValid, isTrusted };
},
ageGate: (value, options = null) => {
const ageGateType = options.ageGateType || 'dob';
const legalAge = options.legalAge;
return ageGate(ageGateType, value, legalAge);
}
};
export { Validators, Checkers };
|