I am trying to assign validation to a text box, SexTextBox
I wish to allow only M or F to be inserted, if the user inserts anything else i want it to throw up an error provider.
So far i have come up with:
This will work to prevent all but M being entered.
I thought that if i wanted to allow M and F creating the following code would work:
It appears to prevent incorrect entry but no error provider is displayed.
Found this forum post seems to explain it:
http://www.developerfusion.co.uk/forums/p/36104/149689/#149689
I wish to allow only M or F to be inserted, if the user inserts anything else i want it to throw up an error provider.
So far i have come up with:
VB.NET:
If Me.SexTextBox.Text <> "M" Then
Me.ErrorProvider1.SetError(SexTextBox, "Enter M or F only!")
Me.SexTextBox.Text = ""
Me.SexTextBox.Focus()
Else
Me.ErrorProvider1.SetError(SexTextBox, "")
End If
This will work to prevent all but M being entered.
I thought that if i wanted to allow M and F creating the following code would work:
VB.NET:
If Me.SexTextBox.Text = "M" Then
Me.ErrorProvider1.SetError(SexTextBox, "")
ElseIf Me.SexTextBox.Text = "F" Then
Me.ErrorProvider1.SetError(SexTextBox, "")
Else
Me.ErrorProvider1.SetError(SexTextBox, "Enter M or F only!")
Me.SexTextBox.Text = ""
Me.SexTextBox.Focus()
End If
It appears to prevent incorrect entry but no error provider is displayed.
Found this forum post seems to explain it:
http://www.developerfusion.co.uk/forums/p/36104/149689/#149689
Last edited: