function PasswordConfirm::validatePasswordConfirm
Validates a password_confirm element.
File
- 
              core/lib/ Drupal/ Core/ Render/ Element/ PasswordConfirm.php, line 106 
Class
- PasswordConfirm
- Provides a form element for double-input of passwords.
Namespace
Drupal\Core\Render\ElementCode
public static function validatePasswordConfirm(&$element, FormStateInterface $form_state, &$complete_form) {
  $pass1 = trim($element['pass1']['#value']);
  $pass2 = trim($element['pass2']['#value']);
  if (strlen($pass1) > 0 || strlen($pass2) > 0) {
    if (strcmp($pass1, $pass2)) {
      $form_state->setError($element, t('The specified passwords do not match.'));
    }
  }
  elseif ($element['#required'] && $form_state->getUserInput()) {
    $form_state->setError($element, t('Password field is required.'));
  }
  // Password field must be converted from a two-element array into a single
  // string regardless of validation results.
  $form_state->setValueForElement($element['pass1'], NULL);
  $form_state->setValueForElement($element['pass2'], NULL);
  $form_state->setValueForElement($element, $pass1);
  return $element;
}Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.
