I’ll get some info from an user using textarea. But he can not type 3 consecutive white space characters, so i invested this code 😀
function trim(myString)
{
str = myString;
str = str.replace(/\s/g, " ");
alert(str.lastIndexOf(" "));
if (str.lastIndexOf(" ")>-1)
{
alert("At most 3 consecutive white Space is allowed !");
return false;
}
return myString.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
but it does not work, can you help me correcting the error ?
The above code first replaces all types of white characters with a space, then it search for 3 consecutive white space, if it founds then it shows an alert !
You can also have a look at Allowing at most 2 newline in textarea
Try with this alternative, simplified version: