mercredi 14 octobre 2015

count string length including 'invisible characters' like \r \n in javascript and php

I am trying to display a "x characters left" text next to a textarea, to see how much still can be written, with javascript / jquery:

var area = 'textarea#zoomcomment';
var c = $(area).val().length;

Then the input is validated with laravel's max validation.

'comment' => 'required|max:3000'

The javascript does not count the \n or \r characters, but PHP/laravel does. Is there a javascript function to count everything , including linebreaks etc ? I'd like to have the same string length with js and php.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire