开发者

Restrict Text Box to only accept 10 digit number

开发者 https://www.devze.com 2023-01-14 23:37 出处:网络
I have a Text Box that is a System::String^, I need to confirm that this only accepts 10 digits numbers an开发者_StackOverflow社区d no letters, symbols, etc. How would I implement this in C++ visual s

I have a Text Box that is a System::String^, I need to confirm that this only accepts 10 digits numbers an开发者_StackOverflow社区d no letters, symbols, etc. How would I implement this in C++ visual studio? Do I need to convert the contents to a std::string first?


Assuming this is a .NET winforms text box (since your snippet is C++/CLI), you want to set the "MaxLength" property. (Something like TextBox^ tb = gcnew TextBox(); tb->MaxLength = 10.)

For the numbers-only part, you want to assign a delegate to the KeyDown and KeyPress events to make sure the entered character is a number. Sample Code is here: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(v=VS.71).aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消