IceAngel89

How do i create a mask that accepts numbers 0-9, no spaces, and at least 1 (length > 0)
currently i am using If - else for the at least 1 char condition
If MaskedTextBox.length = 0 Then
...
End If
but for the 0-9 and no spaces, optional(but at least 1 character)
i tried using 099 but spaces can still be entered
ResetOnSpace property set to true didn't work
i thought of using a KeyDown event:
Private Sub txt_IPinput2_KeyPress(ByVal ...) Handles txt_IPinput2.KeyPress, txt_mask4.KeyPress, txt_mask3.KeyPress, txt_mask2.KeyPress, txt_mask1.KeyPress, txt_mask.KeyPress, txt_IPinput4.KeyPress, txt_IPinput3.KeyPress, txt_IPinput1.KeyPress
Dim control As MaskedTextBox = CType(sender, MaskedTextBox)
If Char.IsWhiteSpace(e.KeyChar) Then
<set to as if the user didn't enter anything> How do i do this
End If
End Sub


Re: Visual Basic Language Mask: optional but no spaces. Number or numbers only textbox entry.

ClaytonM

You're almost there.

e.Handled = True





Re: Visual Basic Language Mask: optional but no spaces. Number or numbers only textbox entry.

Spidermans_DarkSide

Hi,

Set the default text of your textbox to a number then.>>

 

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles TextBox1.TextChanged

 

If IsNumeric(TextBox1.Text) = False Then

MsgBox("Please enter a number!!")

End If

'Deal with the number entered here. :-)

 

End Sub

 

Regards,

S_DS

 

 

 






Re: Visual Basic Language Mask: optional but no spaces. Number or numbers only textbox entry.

IceAngel89

ClaytonM wrote:

You're almost there.

e.Handled = True



i did like
If Char.IsWhiteSpace(e.KeyChar) Then
e.Handled = True
End If
did i do right it didn't work.




Re: Visual Basic Language Mask: optional but no spaces. Number or numbers only textbox entry.

spotty

For what it sounds like your doing and you want to simply validate that the textbox has a numeric entry in then you can do this with a normal textbox. You'll probably want to restrict the textbox to enter numbers only and there are numerous examples of how to do this in the VB forums - search for textbox and numbers only.

This simple code validates that a number has been entered and that it is within a specific numeric range. This would allow decimals to be entered which may not be desirable and adding the numbers only code would prevent the addition of decimal places limiting the numbers to integer only.

Masks are good if you have a fixed format and not a variable one. ie. zip codes are always 5 digits long. Social Security Numbers are 9 digits in specific format.

Public Class Form1
Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim Tb As TextBox = CType(sender, TextBox)
If IsNumeric(Tb.Text) = False Then
MsgBox("Please enter a number!!")
Else
Dim x = CType(Tb.Text, Single)
If x < 0 Or x > 100 Then
MsgBox("Out of range")
End If
End If
End Sub
End Class