trungtranqn91
4 months ago
902
9
Laravel

Validate count max value with text include break line (new line)

Posted 4 months ago by trungtranqn91

Due to the way strlen work, line breaks count as two characters in PHP, but not in Javascript. This can lead to confusion for users who type right up to the limit, click submit, and then page reload without error . even though the Javascript counter doesn't think so.

ex:

Input text:

abcd

efghi

=> 10 character

Validation:

$rules = [
	'text' => 'max:10',
]

Validate by JS is ok . But laravel is not passed.

I realize the break line will be converted to \r\n . That why php count it 2 . Anyone know about this issue please give me the solution. Thank a lot !!!

Please sign in or create an account to participate in this conversation.