RIAS
asked on
Check string entered is valid month
Hello,
Hello in vb.net how can I check if the string entered is the valid month and return the value of the month.
Eg:
Str = Jan
Result: Jan
Str= Fb
Result: Not valid month
Thanks
Hello in vb.net how can I check if the string entered is the valid month and return the value of the month.
Eg:
Str = Jan
Result: Jan
Str= Fb
Result: Not valid month
Thanks
try a function like this:
Function validateMonth(v As String) As String
Dim DateValue As Date
If (Date.TryParse("1 " + v + " 2000", DateValue)) Then
Return v
Else
Return "Not valid month"
End If
End Function
then:Dim Str As String = "Jan"
MessageBox.Show(validateMonth(Str))
Str = "Fb"
MessageBox.Show(validateMonth(Str))
try customize accordingly, for example, return a true/ false from function above instead, etc.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Would it not be better the user has to select a month from eg. a combobox rather than type a month in:It is good idea but, the user wants to type.
Thanks Andy
Thanks Andy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
haha, great! Perfect! Thanks a lot!
ASKER
Thanks all!
You could have an array , a text file , a database table
Each time you get a value you should search if it is matched and accordingly act.
e.g
Fb ...is it February or the user wanted to check news on Facebook and the screen refreshed and took him/her to the application
to be 100% sure just dump the string input and limit the user to a combobox...no need for extra validation ,searching..whatever..the values will always be 12,consistent and valid.