473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How To Cancell Character Entry in a text box?

Hi,
I'd like to be able to enter only letters in my text box. If a user
enters anything except a letter, the key entered would simply not be
displayed in the text box.j
How can I do ;that?

Thank you
Nov 20 '05 #1
10 1288

I got this one by myself :

Inside text box KeyPress events do :

if (char.IsLetter(e.KeyChar) = false) then
e.Handled = true
end if

Thanks anyways

On Mon, 10 May 2004 18:51:50 GMT, Dino Buljubasic
<di**@noplacelikehome.com> wrote:
Hi,
I'd like to be able to enter only letters in my text box. If a user
enters anything except a letter, the key entered would simply not be
displayed in the text box.j
How can I do ;that?

Thank you


Nov 20 '05 #2
* Dino Buljubasic <di**@noplacelikehome.com> scripsit:
I'd like to be able to enter only letters in my text box. If a user
enters anything except a letter, the key entered would simply not be
displayed in the text box.j


I would not restrict the user to enter certain characters. Instead, I
would add a handler to its 'Validating' event and check the content of
the textbox there. If it's not "valid", you can set an errorprovider on
that control.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Herfried:

I'm interested. Why are you advocating asking the user to make an entry,
letting them type whatever they like, and then--only after they've
finished--telling them that they can't use what they've typed?

Thanks,
Russell Jones,
Executive Editor, DevX.com
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2g***********@uni-berlin.de...
* Dino Buljubasic <di**@noplacelikehome.com> scripsit:
I'd like to be able to enter only letters in my text box. If a user
enters anything except a letter, the key entered would simply not be
displayed in the text box.j


I would not restrict the user to enter certain characters. Instead, I
would add a handler to its 'Validating' event and check the content of
the textbox there. If it's not "valid", you can set an errorprovider on
that control.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #4
* "Russell Jones" <ar**@nospam.northstate.net> scripsit:
I'm interested. Why are you advocating asking the user to make an entry,
letting them type whatever they like, and then--only after they've
finished--telling them that they can't use what they've typed?


For example, if I copy something to the clipboard and paste it into the
textbox, then edit it to make it "valid". Preventing the user from doing
that (pasting/editing) whatever he/she wants, is IMO annoying. That's
why the ErrorProvider component was made available.

Just my 2 Euro cents.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
>
For example, if I copy something to the clipboard and paste it into the
textbox, then edit it to make it "valid". Preventing the user from doing
that (pasting/editing) whatever he/she wants, is IMO annoying. That's
why the ErrorProvider component was made available.


And therefore I say always that doing both is the best.

Retyping a full textbox after 10000 characthers is anoying.

Cor

Nov 20 '05 #6
* "Cor Ligthert" <no**********@planet.nl> scripsit:
For example, if I copy something to the clipboard and paste it into the
textbox, then edit it to make it "valid". Preventing the user from doing
that (pasting/editing) whatever he/she wants, is IMO annoying. That's
why the ErrorProvider component was made available.
And therefore I say always that doing both is the best.


Mhm... I want a great user experience without restrictions.
Retyping a full textbox after 10000 characthers is anoying.


Who said that you must do that?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #7
Herfried:

I agree with you that pasting and editing out invalid characters is a
convenient feature. But trapping the Keypress event (as the original
poster's code does) to prevent users from *typing* invalid characters
doesn't prevent users from pasting text in--nor from editing it. Of course
you should validate the completed entry as well.... So my original question
still stands: Do you still feel that preventing users from entering invalid
characters should only be done at the end of the edit?

Thanks,
Russell

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2g***********@uni-berlin.de...
* "Russell Jones" <ar**@nospam.northstate.net> scripsit:
I'm interested. Why are you advocating asking the user to make an entry,
letting them type whatever they like, and then--only after they've
finished--telling them that they can't use what they've typed?


For example, if I copy something to the clipboard and paste it into the
textbox, then edit it to make it "valid". Preventing the user from doing
that (pasting/editing) whatever he/she wants, is IMO annoying. That's
why the ErrorProvider component was made available.

Just my 2 Euro cents.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #8

I guess, the right way would be to do both but in my case, the text
box is actually a search entry, each time a user enters a letter, on
keyUp a search will be performed to find names starting with the
letter or letters entered.

Therefore, probably the best would be to do it as I did, to simply
ignore all characters that are not letters (except the Backspace)

Dino
On Mon, 10 May 2004 18:51:50 GMT, Dino Buljubasic
<di**@noplacelikehome.com> wrote:
Hi,
I'd like to be able to enter only letters in my text box. If a user
enters anything except a letter, the key entered would simply not be
displayed in the text box.j
How can I do ;that?

Thank you


Nov 20 '05 #9
* "Russell Jones" <ar**@nospam.northstate.net> scripsit:
I agree with you that pasting and editing out invalid characters is a
convenient feature. But trapping the Keypress event (as the original
poster's code does) to prevent users from *typing* invalid characters
I agree, but I am afraid that this may confuse users.
doesn't prevent users from pasting text in--nor from editing it. Of course
you should validate the completed entry as well.... So my original question
still stands: Do you still feel that preventing users from entering invalid
characters should only be done at the end of the edit?


That's my personal opinion, but I know that it has its disadvantages.
When editing very complex strings, using a masked edit control or a
datetimepicker will be much easier, but it will prevent the user from
in-place editing.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #10
* Chris Dunaway <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net"> scripsit:
Inside text box KeyPress events do :

if (char.IsLetter(e.KeyChar) = false) then
e.Handled = true
end if


A little simpler would be:

e.Handled = Not Char.IsLetter(e.KeyChar)


.... but this would assign a value to 'e.Handled' even if it's not
necessary...

SCNR ;-)

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mudcat | last post by:
Howdy, I have a simple combox that I have commands entered into which looks like this: """This is a list with the commands to be run in rotisserie fasion.""" self.comList =...
0
by: BW | last post by:
Please ignore the rest of the code, except for the highlighted part (or the line 'ent1=Entry(topf, width=25)' to line 'ent1.insert(INSERT, wrong, if you cannot see the color). You can copy this into...
7
by: Michael Onfrek | last post by:
Hi! I'm playing with entry again and trying to restrict length of entry widget to certain number of character, so users cannot enter more character into it. Any ideas? Reg. Michael Onfrek
2
by: Gary | last post by:
Morning all, I have a form field called: Bsk01 How do I onBlur prompt the user to enter a ZERO as character one, if one is not already entered. At the same time, I would like to ensure at...
18
by: james | last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits the "," and then copies the results into a listbox. The data also...
1
by: clusardi2k | last post by:
Hello, the step that I did to get to my current question are: I began to use the keyword DataDirectory and the next line of code. When I ran the application, I would be asked for a Login ID and...
39
by: Umesh | last post by:
Plese help. Is there any software by which we can do that?
11
by: S N | last post by:
how to print apostrophe character ' and double quote " in asp using vbscript. my code using response.write replaces " character with inverted question mark. please help
50
by: arunajob | last post by:
Hi all, If I have a piece of code something like this void main(void) { char * p1="abcdefghijklmn"; ............................................. }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.