Hello All,
I have the following statements for textbox validation, but the Statemet I use to validate maxlength doesn't work. Would you please help me take a look at it to see what i did wrong... Thank you very much!!!
If the user enters the RecordNumber that is less than 5 digit, it prompts the user to re-enter as it conists of 5 digits.
This one doesn't work. Then I broke it down into separate if statements....
----------------------------------------------------------------------------------------------
Private Function ValidateFields() As Boolean
If Trim(Replace(Me.txtClientIdNumber.Text, "'", "")) = "" OrElse Trim(Replace(Me.txtClientIdNumber.Text, "'", "")) = "0" OrElse Trim(Replace(Me.txtClientIdNumber.Text, "'", "")) = "00" OrElse Trim(Replace(Me.txtClientIdNumber.MaxLength, "'", "")) < 7 Then
MsgBox("You must enter a Client ID Number that consists of 7 digits. It must start with any number from 1 to 9, NOT 0 or 00.")
Return False
End If
Return True
End Function
----------------------------------------------------------------------------------------------
Private Function ValidateFields() As Boolean
If Trim(Replace(Me.txtRecordNumber.Text, "'", "")) = "" Then
MsgBox("You must enter a Record Number.")
Return False
ElseIf txtRecordNumber.Text.Trim.StartsWith("0") Then
MsgBox("The Record Number cannot start with 0. It can start with any number from 1 to 9.")
Return False
ElseIf txtRecordNumber.Text.Trim.StartsWith("00") Then
MsgBox("The Record Number cannot start with 00. It can start with any number from 1 to 9.")
Return False
ElseIf Trim(Replace(Me.txtRecordNumber.MaxLength, "'", "")) < 7 Then
MsgBox("The Record Number consists of 7 digits.")
Return False End If
Return True
End Function
'Validate textboxes and Add New Record to the database table
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If ValidateFields() Then SaveRecord()
End Sub
I have the following statements for textbox validation, but the Statemet I use to validate maxlength doesn't work. Would you please help me take a look at it to see what i did wrong... Thank you very much!!!
If the user enters the RecordNumber that is less than 5 digit, it prompts the user to re-enter as it conists of 5 digits.
This one doesn't work. Then I broke it down into separate if statements....
----------------------------------------------------------------------------------------------
Private Function ValidateFields() As Boolean
If Trim(Replace(Me.txtClientIdNumber.Text, "'", "")) = "" OrElse Trim(Replace(Me.txtClientIdNumber.Text, "'", "")) = "0" OrElse Trim(Replace(Me.txtClientIdNumber.Text, "'", "")) = "00" OrElse Trim(Replace(Me.txtClientIdNumber.MaxLength, "'", "")) < 7 Then
MsgBox("You must enter a Client ID Number that consists of 7 digits. It must start with any number from 1 to 9, NOT 0 or 00.")
Return False
End If
Return True
End Function
----------------------------------------------------------------------------------------------
Private Function ValidateFields() As Boolean
If Trim(Replace(Me.txtRecordNumber.Text, "'", "")) = "" Then
MsgBox("You must enter a Record Number.")
Return False
ElseIf txtRecordNumber.Text.Trim.StartsWith("0") Then
MsgBox("The Record Number cannot start with 0. It can start with any number from 1 to 9.")
Return False
ElseIf txtRecordNumber.Text.Trim.StartsWith("00") Then
MsgBox("The Record Number cannot start with 00. It can start with any number from 1 to 9.")
Return False
ElseIf Trim(Replace(Me.txtRecordNumber.MaxLength, "'", "")) < 7 Then
MsgBox("The Record Number consists of 7 digits.")
Return False End If
Return True
End Function
'Validate textboxes and Add New Record to the database table
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If ValidateFields() Then SaveRecord()
End Sub