Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,10 @@ protected function getDateTime($value)
public function validateAlpha($attribute, $value, $parameters)
{
if (isset($parameters[0]) && $parameters[0] === 'ascii') {
return is_string($value) && preg_match('/^[a-zA-Z]+$/u', $value);
return is_string($value) && preg_match('/\A[a-zA-Z]+\z/u', $value);
}

return is_string($value) && preg_match('/^[\pL\pM]+$/u', $value);
return is_string($value) && preg_match('/\A[\pL\pM]+\z/u', $value);
}

/**
Expand All @@ -370,10 +370,10 @@ public function validateAlphaDash($attribute, $value, $parameters)
}

if (isset($parameters[0]) && $parameters[0] === 'ascii') {
return preg_match('/^[a-zA-Z0-9_-]+$/u', $value) > 0;
return preg_match('/\A[a-zA-Z0-9_-]+\z/u', $value) > 0;
}

return preg_match('/^[\pL\pM\pN_-]+$/u', $value) > 0;
return preg_match('/\A[\pL\pM\pN_-]+\z/u', $value) > 0;
}

/**
Expand All @@ -391,10 +391,10 @@ public function validateAlphaNum($attribute, $value, $parameters)
}

if (isset($parameters[0]) && $parameters[0] === 'ascii') {
return preg_match('/^[a-zA-Z0-9]+$/u', $value) > 0;
return preg_match('/\A[a-zA-Z0-9]+\z/u', $value) > 0;
}

return preg_match('/^[\pL\pM\pN]+$/u', $value) > 0;
return preg_match('/\A[\pL\pM\pN]+\z/u', $value) > 0;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4547,6 +4547,9 @@ public function testValidateAlpha()

$v = new Validator($trans, ['x' => 'abc123'], ['x' => 'Alpha']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['x' => "abc\n"], ['x' => 'Alpha']); // ends with newline
$this->assertFalse($v->passes());
}

public function testValidateAlphaNum()
Expand All @@ -4566,6 +4569,9 @@ public function testValidateAlphaNum()

$v = new Validator($trans, ['x' => 'नमस्कार'], ['x' => 'AlphaNum']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['x' => "abc\n"], ['x' => 'AlphaNum']); // ends with newline
$this->assertFalse($v->passes());
}

public function testValidateAlphaDash()
Expand All @@ -4582,6 +4588,9 @@ public function testValidateAlphaDash()

$v = new Validator($trans, ['x' => '٧٨٩'], ['x' => 'AlphaDash']); // eastern arabic numerals
$this->assertTrue($v->passes());

$v = new Validator($trans, ['x' => "abc\n"], ['x' => 'AlphaDash']); // ends with newline
$this->assertFalse($v->passes());
}

public function testValidateAlphaWithAsciiOption()
Expand Down Expand Up @@ -4630,6 +4639,9 @@ public function testValidateAlphaWithAsciiOption()

$v = new Validator($trans, ['x' => 'abc123'], ['x' => 'Alpha:ascii']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['x' => "abc\n"], ['x' => 'Alpha:ascii']); // ends with newline
$this->assertFalse($v->passes());
}

public function testValidateAlphaNumWithAsciiOption()
Expand All @@ -4652,6 +4664,9 @@ public function testValidateAlphaNumWithAsciiOption()

$v = new Validator($trans, ['x' => 'नमस्कार'], ['x' => 'AlphaNum:ascii']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['x' => "abc\n"], ['x' => 'AlphaNum:ascii']); // ends with newline
$this->assertFalse($v->passes());
}

public function testValidateAlphaDashWithAsciiOption()
Expand All @@ -4671,6 +4686,9 @@ public function testValidateAlphaDashWithAsciiOption()

$v = new Validator($trans, ['x' => '٧٨٩'], ['x' => 'AlphaDash:ascii']); // eastern arabic numerals
$this->assertFalse($v->passes());

$v = new Validator($trans, ['x' => "abc\n"], ['x' => 'AlphaDash:ascii']); // ends with newline
$this->assertFalse($v->passes());
}

public function testValidateTimezone()
Expand Down