function Random::stringValidate

Same name in other branches
  1. 10 core/tests/Drupal/TestTools/Random.php \Drupal\TestTools\Random::stringValidate()

Callback for random string validation.

Parameters

string $string: The random string to validate.

Return value

bool TRUE if the random string is valid, FALSE if not.

See also

\Drupal\Component\Utility\Random::string()

File

core/tests/Drupal/TestTools/Random.php, line 76

Class

Random
Provides random generator utility static methods.

Namespace

Drupal\TestTools

Code

public static function stringValidate(string $string) : bool {
    // Consecutive spaces causes issues for link validation.
    if (preg_match('/\\s{2,}/', $string)) {
        return FALSE;
    }
    // Starting or ending with a space means that length might not be what is
    // expected.
    if (preg_match('/^\\s|\\s$/', $string)) {
        return FALSE;
    }
    return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.