❗ [Help] Numeric textboxes and email filter. [solved]

Posts 1–7 of 7 · Page 1 of 1
❗ [Help] Numeric textboxes and email filter. [solved]
ok i have 2 questions.
1. how can i make textbox with numbers only
2. how can i make email adress textbox
hope you help
I don't understand what you're asking...
Select Case e.Keys
Case Keys.A
Textbox1.text = textbox1.text.replace("a","")
Case keys.b
'Etc.
End select
Quote Originally Posted by user782106 View Post
Select Case e.Keys
Case Keys.A
Textbox1.text = textbox1.text.replace("a","")
Case keys.b
'Etc.
End select
I lol'd at that.

Top cent has the right idea, but you should also allow for the backspace/delete keys:

[highlight=vb.net]
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Dim allowedKeys As Integer() = {Keys.Delete, Keys.Back}
If Not (Integer.TryParse(e.KeyChar, Nothing) _
OrElse allowedKeys.Contains(Asc(e.KeyChar))) Then
e.Handled = True
End If
End Sub
[/highlight]

So yeah, you get the idea. Preferably you would declare your "allowed" keys array outside of the method at class level or something, it would make it more efficient than declaring an array every time you press a key. I just couldn't be bothered.
put that code in key press event of the textbox
Code:
        Dim i As Integer = 0
        If Integer.TryParse(e.KeyChar, i) = False Then
            e.Handled = True
        End If
2- use masked textbox
Numerical up/down is in visual studio just use that and for email

bool isemail = false;
if(!textbox.text.contains(@"@"))
{
isemail = true;
}
else
{
isemail = false
}


that c# just use the same functions in VB only convert them to work.
thanx guys!
/solved
Posts 1–7 of 7 · Page 1 of 1
This thread is closed for replies.
Talk with us