Every time someone types in a decimal or any characters or strings, I want a message box shown saying “only integers”.
Asked
Active
Viewed 46 times
0
-
1Do you want to determine this as the user is typing or do you have some kind of button in your using that confirms the value inputted in your textbox? Or possibly detect the type of content once the user finishes to type in your textbox ? – Kevin Avignon Feb 28 '18 at 00:28
-
2Can you please elaborate your question a bit more? – Carlos Parra Feb 28 '18 at 00:29
-
3What is “a textbox”? WinForm? WPF? ASP.NET? UWP? – Dour High Arch Feb 28 '18 at 00:33
-
You are that much more likely to get better help if you show what you have or tried. Also, be specific about the type of project Web, desktop, etc. – DaniDev Feb 28 '18 at 00:55
-
Show us a little bit of your code... – morha13 Feb 28 '18 at 00:59
1 Answers
0
In .net as your tag says: Try pasting this in some event of the Textbox, for example the Lostfocus. Remember to add the Namespace part:
Imports System.Text.RegularExpressions 'At the top of the form class
Public Class FormName
Private Sub Tbx_EscuelaElegida_LostFocus(.....
'DECLARE VARIABLE AND ASSIGN THE TEXTBOX CONTENT TO IT
Dim TestsVariable As String = TextboxName.text
'IF IT DOES NOT CONTAIN INTEGERS, SHOW A MESSAGE
If Not Regex.IsMatch(TestsVariable, "^[0-9 ]+$") Then
MsgBox("No Decimal Numbers")
End If
End sub
End Class

Sergio Frías
- 1
- 3
-
1
-
I know, Dani. I just answered that because if you look at his tags he included ".net" . So I thought he might know how to write some code in ".net", too and then adapt it to C# :D – Sergio Frías Feb 28 '18 at 01:26