Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Formatting a mmTextBox to input only numbers
Message
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01013395
Message ID:
01013474
Vues:
22
Unfortunately the Masked Edit text box went away with VS.NET.
It will reappear in VS 2005 and is available with third party controls (e.g. Infragistics).

All that aside, a possible way to do this is to handle a text box event when you want the validtion to occur (e.g. KeyPress, Leave, LostFocus, ModifiedChanged, TextChanged, Validated, Validating) with a regular expression validation (or ,even better, perhaps call a MM.NET rules object that contains a regular expression validation routine - if that is able to be done in MM.NET).
The Regular Expression checks the controls text value for an acceptable "Matching" pattern (numbers in your example). Good tool to help with RegEx http://www.regexbuddy.com/index.html

Alternatively you could code something like the following in the textbox's KeyPress event handler:
if( !char.IsNumber(e.KeyChar) & (Keys)e.KeyChar != Keys.Back & e.KeyChar != '.' )
{
e.Handled= true;
}

Another option would be to use WinForms validator controls. See the following for more details: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet04082003.asp

Lastly, if this is a common scenario, create a custom control that inherits from mmTextBox class and adds input validation functions, required validation functions and MaskEdit.
An example is found at: http://www.codeproject.com/vb/net/validtext3.asp
THANKS
Joe Salvatore, Programmer/Analyst - The Stellar Group
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform