I want to ask you

If i want to check length from input, but when the user is add new line i want the length to decrease 2 chars

for example this string :

Hello
World

I want this string to be 12 chars, because Hello 5 chars + 2 chars because the new line and 5 chars for the World

but in another side if the string is:
Hello World
I want the length to be 11 chars because 5 for the 'Hello' and 1 for the space and 5 for the 'World'

I'm not sure exactly what you want but this sort of thing is very simple with regular expressions.

Maybe you want to strip all white space or just carriage returns/linefeeds:

function stripWhiteSpace(str) {
    return str.replace(/\s/g, '');
}

function stripReturns(str) {
    return str.replace(/[\n\r]/g, '');
}

You can see these functions working here.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.