Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Formatting a mmTextBox to input only numbers
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01013395
Message ID:
01013474
Views:
21
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform