I am developing vb.net - windows application.
I have one text box in which, user supposed to enter data. I have put some validations like, user can put only numbers,alphabets and comma. ( No other symbols.) Its working fine, but I want to put restriction that only one comma should inserted not more than one.
How to do this ?
I have below code for key press event of text box.
ReadOnly ValidChars As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,"
Private Sub txtNewFlatName_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtNewFlatName.KeyPress
Select Case e.KeyChar
Case Convert.ToChar(Keys.Enter) ' Enter is pressed
' Call method here...
Case Convert.ToChar(Keys.Back) ' Backspace is pressed
e.Handled = False ' Delete the character
Case Chr(22) ' CTRL+V is pressed
' Paste clipboard content only if contains valid characters
e.Handled = If(Clipboard.GetText().All(Function(c) ValidChars.Contains(c)), False, True)
Case Else ' Other key is pressed
e.Handled = Not (ValidChars.IndexOf(e.KeyChar) > -1)
End Select
End Sub