asp.net - Difference between JQuery .length() and .NET .Length for Returns -
I wrote a function of jQuery to check the total number of characters in a given text box and warn Pop up maximum (user-defined) length Example: (very simplified):
function check lang (txt) {if (txt.length> gtl = maxlength) {warnings ('enter too much text '); return false; } And true back; }
It works as expected, but like a good developer, I also perform server-side verification against the field length (on my domain object) in the field. I am
It is that I have seen that the following string:
12 <34>
(where
clearly returning character)
The length of 5 will return to Javascript and length as 6 .net (String.Length) Will return in
Am I missing something here? Or would I have to compute the number of returns in the Javascript string and then repeat them to get 'right' .net count? Any indication on how to handle it?
Update: According to the suggestions given below, I can actually get the right length.
function GetCurrentLength (txt) {return.txt.treplace (/ \ n / g, "\ n \ r"). Length; }
However, apart from detection of character count, there is more to the question because once the system detects that too many letters are entered, then this (client-side ) Far away (this can be more than one, because users can copy-paste too many text in the text box).
Something like this:
if (textLength> maxlength) {self.val (text.Subutra (0, MacLenth)); }
If I count double returns then surely I will get in trouble because the wrong number of letters is threatened to be removed. How can I correctly delete the correct numbers?
This was my last solution, it seems a little dirty, but works. Calculate the length of the string
//, but instead of one, keep in mind to calculate the returns for 2 characters instead of 2, like this, we should get the same length as NET function GetCurrentLength (txt) {return txt.length + GetNumberOfReturns (txt); } GetNumberOfReturns (txt) function {var number equal to 0 var enterRegExpr = txt.match (/ \ n / g); If (enterRegExpr) numberOfReturns = enterRegExpr.length; Return numberofRighton; } Function katomoxylanth (TXTT, McLentham) {return txt.substr (0, Mactland - Gatnumber Overturn (TSTT)); }
Comments
Post a Comment