${message}
`; errorBox.style.display = 'flex'; } // remove an input message on and form input value function hideInputError(target) { removeClassFromTarget(target, 'alertOn'); const errorBox = document.getElementById(`${target.id}-error`); errorBox.style.display = 'none'; } // process validation for username function validateEmail(email) { // Used regex from here: // https://www.w3resource.com/javascript/form/email-validation.php const regex = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/); const matchEmail = (email) => (regex.test(email)) ? "valid" : "invalid"; let errorMsg = ''; let status = ''; if (email.length == 0) { status = 'empty'; errorMsg = errorList.enter_email.description; } else if (matchEmail(email) == "invalid") { status = 'watching'; errorMsg = errorList.password_format.description; } else { status = 'ready'; } return { status, errorMsg }; } // process validation for password function validatePassword(password, emptyOnly) { let matches = matchPasswordRules(password); if (emptyOnly) { matches = 'valid'; } let errorMsg = ''; let status = ''; if (password.length == 0) { status = 'empty'; errorMsg = errorList.enter_password.description; } else if (matches.indexOf('invalid') > -1) { status = 'watching'; errorMsg = errorList.all_password.description; } else { status = 'ready'; } return { status, matches, errorMsg }; } // match each password rule function matchPasswordRules(password) { const matches = []; const rules = [ new RegExp('^(?=.{8,}).*$'), // Has 8 characters. new RegExp('^(?=.*[A-Z]).*$'), // Has 1 uppercase character. new RegExp('^(?=.*[a-z]).*$'), // Has 1 lowercase character. new RegExp('^(?=.*[0-9]).*$'), // Has 1 number character. ]; for (let i = 0; i < rules.length; i++) { matches[i] = (rules[i].test(password)) ? 'valid' : 'invalid'; } return matches; } // add a class to an input target function addClassToTarget(target, classname) { const classArr = target.getAttribute('class').split(' '); classArr.push(classname); const newClassArr = classArr.filter((i, p) => classArr.indexOf(i) == p); target.setAttribute('class', newClassArr.join(' ')); } // remove a class from an input target function removeClassFromTarget(target, classname) { const classArr = target.getAttribute('class').split(' '); const newClassArr = classArr.filter((i, p) => ((i != classname) && (classArr.indexOf(i) == p))); target.setAttribute('class', newClassArr.join(' ')); } function getDomain(href) { const urlParser = document.createElement('a'); let url = href; if (href === undefined) { url = window.location.hostname; } urlParser.href = url; let domain = urlParser.hostname; if (domain.substr(0, domain.lastIndexOf('.')).lastIndexOf('.') > -1) { domain = domain.substr(domain.substr(0, domain.lastIndexOf('.')).lastIndexOf('.') + 1) } return domain; } function setCookie(key, value, expiry, domain) { const expires = new Date(); const host = getDomain(domain); expires.setTime(expires.getTime() + (expiry * 24 * 60 * 60 * 1000)); document.cookie = key + '=' + value + ';path=/;domain=' + host + ';' + 'expires=' + expires.toUTCString(); } function eraseCookie(key) { var keyValue = this.getCookie(key); this.setCookie(key, keyValue, -1, auth0config.brandDomain); } function getCookie(key) { var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)'); return keyValue ? keyValue[2] : null; } function readCookie(name) { const cookie = getCookie(name); try { const cookieJson = JSON.parse(cookie); return cookieJson; } catch (e) { } return {}; } function getUrlParameter(name) { name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); var results = regex.exec(location.search); return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); }; function setHidCookie(hashId, domain) { setCookie('hid', hashId, 365, domain); }

Sign Up

Join now and become a part of the Southern Living Community.

Have an account? Sign In
真钱炸金花