I have a javascript function that forces a space after every 26 letters
function nospaces(t)
{
if(t.value.match(/\S{27}/g))
{
//alert('Sorry, you can not enter a word more than 26 characters long');
t.value[5]=t.value.replace(/\S{27}/g,'');
}
}
Now i want that every 27th letter that user enter instead of space should replaced by space
Make smart use of regex groups, if
\S{26}is followed by a\Sreplace the whole match with the first group followed by a space;var foo = 'abcdefghijklmnopqrstuvwxyzab'.replace(/(\S{26})(\S)/, '$1 ');gives:
abcdefghijklmnopqrstuvwxyz b