2

When I enter some text and then enter some new lines using test.length does not count new lines in the string. I'm using this text to send SMS messages which are sensitive to all newlines so it all has to count. Any ideas?

Hit enter 4 times and see the counter doesn't go up.

http://codepen.io/clouddueling/pen/HJAfn

2 Answers 2

3

You need an ng-trim="false" to avoid automatic trimming: http://codepen.io/musically_ut/pen/KHBto

The documentation for this is missing but there is an pull request on the way.

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm... did not know about ng-trim. Thanks for expanding my knowledge!
0

The control characters for CRLF (\r\n) typically don't count in the length of a string. You can detect them with a matching regex and use the number of matches to increment your character count. Something like this:

var crlfCount = mytext.match(/[\n\r]|[\r\n]/g);
linecount += crlfCount.length;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.