4 Replies - 311 Views - Last Post: 10 December 2012 - 08:10 PM Rate Topic: -----

#1 Zeaky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 21-October 12

Checking if a Number is Entered?

Posted 10 December 2012 - 07:35 PM

I'm trying to check if a number is entered in a textbox. Yes, I know how to use IsNumeric, but that's not what I need. Let's say someone gives you a form that has something like First Name with a textbox next to it. Then they enter something along the lines of Harry1234. I don't want them to be able to enter numbers. How can I go about verifying that they didn't?

Please explain as simply as possible, I'm still learning. Thanks for your help.

Is This A Good Question/Topic? 0
  • +

Replies To: Checking if a Number is Entered?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9197
  • View blog
  • Posts: 34,551
  • Joined: 12-June 08

Re: Checking if a Number is Entered?

Posted 10 December 2012 - 07:38 PM

The brute force method is hook the 'key down' event for that textbox.. in that event is an event arg that says the key coming in.. if that key is a letter.

http://msdn.microsof...r.isletter.aspx

or you can make it a masked textbox and set the mask to be only alpha characters...
or you can hook into the 'losing focus' so when the user leaves the textbox you can see if there's a number in there.. if so put the focus back in the textbox and throw a verbal warning at them.

There are many ways to do this but pick one that works for your project.
Was This Post Helpful? 1
  • +
  • -

#3 Zeaky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 21-October 12

Re: Checking if a Number is Entered?

Posted 10 December 2012 - 07:44 PM

Hm. So if I wanted to use the keydown event, I'd have to display a message to the user as soon as they press down a number key? But how does that stop them after I display it?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9197
  • View blog
  • Posts: 34,551
  • Joined: 12-June 08

Re: Checking if a Number is Entered?

Posted 10 December 2012 - 07:45 PM

if you poke around the event args you can cancel the event and stop the key press from being processed through
Was This Post Helpful? 0
  • +
  • -

#5 Zeaky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 21-October 12

Re: Checking if a Number is Entered?

Posted 10 December 2012 - 08:10 PM

After digging for a few minutes I found that the maskedtextbox worked the best. I just made a custom mask with "?" to indicate letters only, and it seems to work great.

Thanks for your help and ideas!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1