js/register.js
// Validate info submitted in form.
Validate info submitted in form.
Validate info submitted in form .
function validateInfo () {
  firstName = $('#firstName').val()
  lastName = $('#lastName').val()
  region = $('#region').val()
  emailAddress = $('#emailAddress').val()
  password = $('#createPassword').val()
  confirmPassword = $("#confirmPassword").val()
  if (radioValue !== 'on') $('#agreeMessage').show()
  else $('#agreeMessage').hide()
  let emailRegexPtn = /^([a-zA-Z0-9_.-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/
  let isValidEmail = emailRegexPtn.test(emailAddress)
  let containsPlus = emailAddress.includes('+')
  if (!isValidEmail) {
      $('#invalidEmail').show()
      if (containsPlus) {
        $('#invalidEmailWithPlus').show()
      }
  } else {
        $('#invalidEmail').hide()
        $('#invalidEmailWithPlus').hide()
  }
  if(password.length < 8) {
    $('#passwordTooShort').show()
    passwordLength = false
  } else {
    $('#passwordTooShort').hide()
    passwordLength = true
  }
  if(password != confirmPassword) {
    $('#passwordErrorMatch').show()
  } else {
      $('#passwordErrorMatch').hide()
  }
  const includesSpecialCharacter = /.*[~!@#$%^&*()<>,.:/?=]/
  const includesUppercase = /[A-Z]/
  const includesNumber = /\d/
  if(!includesSpecialCharacter.test(password)) {
    $('#passwordSpecialCharacterNeeded').show()
  } else {
    $('#passwordSpecialCharacterNeeded').hide()
  }
  if(!includesUppercase.test(password)) {
    $('#passwordUppercaseNeeded').show()
  } else {
    $('#passwordUppercaseNeeded').hide()
  }
  if(!includesNumber.test(password)) {
    $('#passwordNumberNeeded').show()
  } else {
    $('#passwordNumberNeeded').hide()
  }
  passwordStrength = new RegExp('^(?=.*[A-Z])(?=.*[0-9])(?=.*[~!@#$%^&*()<>,.:/?=])')
  if (password.match(passwordStrength)){
    $('#passwordErrorStrength').hide()
    passwordPassed = true
  } else {
    $('#passwordErrorStrength').show()
    passwordPassed = false
  }
  if (firstName && lastName && region && emailAddress && password && confirmPassword) {
    $('#allFields').hide()
  } else {
    $('#allFields').show()
  }
  const isValidForm = (firstName && lastName && region && emailAddress && isValidEmail && password && confirmPassword && passwordLength && passwordPassed) && (radioValue == "on") && (password == confirmPassword)
  if (!isValidForm && window.hj) {
    window.hj('formSubmitFailed')
  }
  return isValidForm
}
function validateInfo ( ) { firstName = $ ( '#firstName' ) . val ( ) lastName = $ ( '#lastName' ) . val ( ) region = $ ( '#region' ) . val ( ) emailAddress = $ ( '#emailAddress' ) . val ( ) password = $ ( '#createPassword' ) . val ( ) confirmPassword = $ ( "#confirmPassword" ) . val ( ) if ( radioValue !== 'on' ) $ ( '#agreeMessage' ) . show ( ) else $ ( '#agreeMessage' ) . hide ( ) let emailRegexPtn = / ^([a-zA-Z0-9_.-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$ / let isValidEmail = emailRegexPtn . test ( emailAddress ) let containsPlus = emailAddress . includes ( '+' ) if ( ! isValidEmail ) { $ ( '#invalidEmail' ) . show ( ) if ( containsPlus ) { $ ( '#invalidEmailWithPlus' ) . show ( ) } } else { $ ( '#invalidEmail' ) . hide ( ) $ ( '#invalidEmailWithPlus' ) . hide ( ) } if ( password . length < 8 ) { $ ( '#passwordTooShort' ) . show ( ) passwordLength = false } else { $ ( '#passwordTooShort' ) . hide ( ) passwordLength = true } if ( password != confirmPassword ) { $ ( '#passwordErrorMatch' ) . show ( ) } else { $ ( '#passwordErrorMatch' ) . hide ( ) } const includesSpecialCharacter = / .*[~!@#$%^&*()<>,.:/?=] / const includesUppercase = / [A-Z] / const includesNumber = / \d / if ( ! includesSpecialCharacter . test ( password ) ) { $ ( '#passwordSpecialCharacterNeeded' ) . show ( ) } else { $ ( '#passwordSpecialCharacterNeeded' ) . hide ( ) } if ( ! includesUppercase . test ( password ) ) { $ ( '#passwordUppercaseNeeded' ) . show ( ) } else { $ ( '#passwordUppercaseNeeded' ) . hide ( ) } if ( ! includesNumber . test ( password ) ) { $ ( '#passwordNumberNeeded' ) . show ( ) } else { $ ( '#passwordNumberNeeded' ) . hide ( ) } passwordStrength = new RegExp ( '^(?=.*[A-Z])(?=.*[0-9])(?=.*[~!@#$%^&*()<>,.:/?=])' ) if ( password . match ( passwordStrength ) ) { $ ( '#passwordErrorStrength' ) . hide ( ) passwordPassed = true } else { $ ( '#passwordErrorStrength' ) . show ( ) passwordPassed = false } if ( firstName && lastName && region && emailAddress && password && confirmPassword ) { $ ( '#allFields' ) . hide ( ) } else { $ ( '#allFields' ) . show ( ) } const isValidForm = ( firstName && lastName && region && emailAddress && isValidEmail && password && confirmPassword && passwordLength && passwordPassed ) && ( radioValue == "on" ) && ( password == confirmPassword ) if ( ! isValidForm && window . hj ) { window . hj ( 'formSubmitFailed' ) } return isValidForm }
Validate info submitted in form.
Validate info submitted in form .
// Ensure "agree button" was clicked. // TODO: This code doesn't seem to actually ensure anything... // Ensure email is valid. // hide has no effect if already hidden so not necessary to track if it was previously visible or not // Check password length. // Check that passwords match. // Check that password meets requirements. //make sure all fields are filled // current acceptance criteria as of 9/3/19 for hotjar form submit metrics are to tally an error for //  "Anything that would cause a submit to fail (i.e. both invalid form values and network errors)."