Textbox control - limiting input

L

LAL

Greetings...

I'm pretty new to ASP.NET programming and I have two questions:

1. How can I automatically change what it typed into a text box to upper
case as the user is typing on the webpage?

I tried the following suggestion
http://www.dotnet247.com/247reference/msgs/33/166114.aspx
(Basically add a script to call .ToUpperCase on the value of control passed
in, the call this script in onKeyUp event)
but onKeyUp doesn't appear to be a recognized event on the TextBox control.

2. Is there a way to limit what the user types to be numeric characters
only? In other word, 1234567890 would be the only accepted characters?

Thanx!
LAL
 
L

LAL

Greetings...

So what you're saying is, "It can't be done." *deep sigh* It sounded like
such an easy request. Oh well.

LAL
 
D

Dan Forster

For Q 2:

You can use the following javascript:

function nb_numeralsOnly(evt)

{

evt = (evt) ? evt : event;

var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode
: ((evt.which) ? evt.which : 0));

if (charCode > 31 && (charCode < 48 || charCode >57)) {return false;}

return true;

}

and bind :

onkeypress='return nb_numeralsOnly(event);'

for Question 1 you could use:

function setUpper(evt)
{

evt = (evt) ? evt : event;
var kc = evt.keyCode;
if (kc>96 && kc<123)
{
evt.keyCode=kc-32;
}
return true;
}

This will still allow other characters but translates lower case
non-accented latin characters to upper case while typing.

bind in the same way as above.

onkeypress='return setUpper(event);'

Dan
 

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,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top