Forum Moderators: open

Message Too Old, No Replies

Prevent characters in a text box

         

aspdaddy

5:00 pm on Dec 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi how can i prevent commas from being entered into a text box? Thanks

whoisgregg

5:30 pm on Dec 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One way:
<input type="text" onkeyup="this.value=this.value.replace(',','')" value="" />

eelixduppy

2:30 am on Dec 12, 2006 (gmt 0)



What was suggested will work, however make sure that if you do not want commas in the string that you check for that server-side as well since this can be easily avoided.

aspdaddy

11:58 am on Dec 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, the problem is that I cant strip them out server side because I am pulling multiple invoice lines from a form and each line has the same element title so the browser inserts commas.

The data isconverted to arrays & sent to a SQL UDF that parses out the commas and creates multiple lines, so its bit much to re-enginer the whole thing.

Fotiman

4:00 pm on Dec 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This, presumably, is an intranet application where perhaps you have more control over the clients?

As mentioned, if someone has JavaScript disabled, this will do no good. You might be able to do something like insert the form input field via JavaScript as well, so that if JavaScript is disabled, there is no way to enter the data at all. Also, I would attach the listener in an unobtrusive way instead of putting it inline in your HTML.

whoisgregg

4:15 pm on Dec 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fotiman, just so you know (since you are probably noticing a pattern of correcting me), I do write my production code in an unobtrusive style. I just get lazy on forums. I'll try to do better. :)

aspdaddy

5:28 pm on Dec 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Its an extranet on an ssl-vpn but I have very little control over the clients other than only supporting IE6/7. I give the companies that access it suggested IE settings for Intranet Zones but many dont implement them.

Its pretty rare for uk businesses to disable Javascript unless its creating popups or pulling in unsecure urls.

Fotiman

7:21 pm on Dec 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



@whoisgregg

Fotiman, just so you know (since you are probably noticing a pattern of correcting me), I do write my production code in an unobtrusive style. I just get lazy on forums. I'll try to do better. :)

Hehehe... I can tell you know what you're doing. And it's often much easier to post a quick solution, especially in the forums. I don't hold it against you. :)