javascript - Allow at most 3 consecutive whitespaae charecters -


i'll info user using textarea. can not type 3 consecutive white space characters, invested code :d

function trim(mystring) {  str = mystring;  str = str.replace(/\s/g, " ");  alert(str.lastindexof("   "));  if (str.lastindexof("   ")>-1)  {   alert("at 3 consecutive white space allowed !");   return false;  }  return mystring.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' '); } 

but not work, can me correcting error ?

the above code first replaces types of white characters space, search 3 consecutive white space, if founds shows alert !

you can have @ allowing @ 2 newline in textarea

try alternative, simplified version:

 function trim(str)  {       if (str.match(/\s\s\s+/))       {            alert("at 3 consecutive white space allowed !");            return false;       }      return str.replace(/\s\s\s+/g,' ');  } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -