Stopping long text submissions without spaces

B

Boolean

I have a section on my webpage that shows the most recent members who
joined, but I am worried that if someone joines with the name
'aaaaaaaaaaaaaaaaaa' that since there are no spaces that it will
stretch the box it is in and look ugly. What I am trying to do to fix
this by having a script that runs at 'Onsubmit' and checks the
username. Unfortunatly I have no idea how to do this, even though I do
have a small understanding of JS :D

How would I get the following to work in JS?
 
L

Lasse Reichstein Nielsen

What I am trying to do to fix this by having a script that runs at
'Onsubmit' and checks the username.

You should also check on the server. It is easy to bypass client-side
validation, deliberatly or accidentally.
Unfortunatly I have no idea how to do this, even though I do have a
small understanding of JS :D
How would I get the following to work in JS?

------------------
If LEN(Username_from_database) is greater than 8 characters AND the
total Spaces is less that 1, alert 'please limit the length of
continus words'.
------------------

var name = Username_from_database;
if (name.length > 8 && name.indexOf(" ")==-1) {
alert("please limit the length of continus words");
}

That limit might be a problem for, e.g., Christopher, Christian,
Jeramiah, Charlotte, Archibald, etc., if they want to register under
their name. That is, I think a length of 8 is too low a limit.

/L
 
E

Evertjan.

Boolean wrote on 01 feb 2004 in comp.lang.javascript:
I have a section on my webpage that shows the most recent members who
joined, but I am worried that if someone joines with the name
'aaaaaaaaaaaaaaaaaa' that since there are no spaces that it will
stretch the box it is in and look ugly. What I am trying to do to fix
this by having a script that runs at 'Onsubmit' and checks the
username. Unfortunatly I have no idea how to do this, even though I do
have a small understanding of JS :D

How would I get the following to work in JS?

t = "Hello world 1234567890123568"
t = t.replace(/(\S{12})/g,"$1 ")
alert(t)

tested

This will put a space after every 12th non whitespace character.

================================

so:

<form onsubmit='t=document.getElementById("k").value;
t = t.replace(/(\S{12})/g,"$1 ";return true)'>
<input id="k">

not tested
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top