locked
Validation Question For Input Mask RRS feed

  • Question

  • There are a number of textboxes I would like to validate.  I first set up the key press events to only allow key entry's of characters which I feel are valid for this location (i.e. numbers and "." for dollar amounts).  But in addition to this I would also like to ensure that the user entered something valid using an input mask.  This may be a simple question but I couldn't seem to find the answer to it.  If I have a input mask of ###.## and the user enters something like 4321.23, would this throw an error and if so, how should I set up my mask large enough so the user is able to enter large amounts.  thank you!
    Monday, August 10, 2009 2:25 PM

Answers

  • the maskedtextbox control with a ###.### input mask would actually not let the user enter 4321.23.  The control would force the cursor into the 6 positions you identified with # relative to the decimal place.

    if the actual positioning and formatting features of the mask are getting in your way, you might consider just coding a textbox to handle keypresses and filter non-numbers.  Masks create very specific positioning of the cursor, it sounds like you just want some regulation of the input and not a mask.
    • Proposed as answer by Jeff Shan Friday, August 14, 2009 2:48 AM
    • Marked as answer by Martin Xie - MSFT Monday, August 17, 2009 3:08 AM
    Monday, August 10, 2009 2:40 PM

All replies

  • the maskedtextbox control with a ###.### input mask would actually not let the user enter 4321.23.  The control would force the cursor into the 6 positions you identified with # relative to the decimal place.

    if the actual positioning and formatting features of the mask are getting in your way, you might consider just coding a textbox to handle keypresses and filter non-numbers.  Masks create very specific positioning of the cursor, it sounds like you just want some regulation of the input and not a mask.
    • Proposed as answer by Jeff Shan Friday, August 14, 2009 2:48 AM
    • Marked as answer by Martin Xie - MSFT Monday, August 17, 2009 3:08 AM
    Monday, August 10, 2009 2:40 PM
  • take a look at this article http://www.codeproject.com/KB/vb/MaskedTextBox.aspx

    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Monday, August 10, 2009 2:45 PM
  • I rarely use MaskTextBox for currency amounts. Having set up the Keypress, you have several ways of formatting the displayed data. Here is one:

    Dim amount As Decimal

    amount = ????

    TextBox1.Text = amount.ToString("N")



    Only performance counts!
    Monday, August 10, 2009 2:56 PM