Re: Validating a text box
can someone close this..?? already found out how to do it..
Re: Validating a text box
Click on Thread Tools, and then Mark as RESOLVED. Only you can close it out.
Also, it'd help the next person to post the answer to any question.
Thanks
Re: Validating a text box
You should also look at Regular Expressions. You will have to write less code and it will be easier to maintain and understand.
Re: Validating a text box
what's Regular Expressions..??
this is what i did:
Code:
sChar1 = Mid(txtCustomerAccountNumber.text, 1, 1)
If sChar1 <> "A" And sChar1 <> "B" And sChar1 <> "C" And sChar1 <> "X" Then
sErrorMessage = sErrorMessage & "Customer Acount Number should start with A, B, C, or X" & vbCrLf & "e.g. A, B, C or X" & vbCrLf & "e.g. A1234567" & vbCrLf
bErrorOccurred = True
but it didn't work properly... any suggestions..??
Re: Validating a text box
Use a regular expression such as Shuja Ali suggests to make the validation logic.
You can take a look at it here:
http://msdn.microsoft.com/en-us/library/hs600312.aspx
It is a powerful tool and well worth the time to get introduced to.
Re: Validating a text box
Normally I just use an instr statement for such checks.
Code:
Dim ValidChars as String="ABCX"
if instr(ValidChars,Mid(txtCustomerAccountNumber.text, 1, 1))=0 then
' do error stuff here
end if
Re: Validating a text box
Quote:
Originally Posted by manil
hi! i want to make validation on a text box so that the first character is only A, B, C, or X..
...
Code:
Select Case sCustomerAccountNumber.Chars(0)
Case "A", "B", "C", "X"
'Is ok
Case Else
'Is Wrong
sErrorMessage &= "Customer Account Number should start with a letter!" & vbCrLf & _
"e.g. A, B, C or X" & vbCrLf & _
"e.g. A1234567" & vbCrLf
bErrorOccurred = True
End Select
Re: Validating a text box
How about a custom user control that takes a regular expression as a property and an isvalid property that gets set when valid - you could include an error provider in the control.