Validating dates vb

18 Apr

How can I use the range validator to validate a valid date?If I enter 1 January 1000 as the min or max value I get an error saying value cannot be converted to type date, but if I use another format it picks up my entered text as invalid.I believe that the dates have to be specified in the current culture of the application.You might want to experiment with setting Culture Invariant Values to true and see if that solves your problem.Below is my code: This works, but the caveat is that this allows dates that may be out of range of SQL dates less than 1753 or you may have a date range (no future date entries).

(34 printed pages) Introduction Looking at Validation The Required Field Validator Control The Compare Validator Control The Range Validator Control The Regular Expression Validator Control The Custom Validator Control The Validation Summary Control Conclusion In your studies of ASP.The formats for the date string used in this example conform to the US standard of MM/DD/YYYY but that can easily be modified to work with other UI cultures.The method shown may be of use if you have an application that receives dates as strings rather than as actual Date Time values.NET, you might have been introduced to a number of different types of controls, whether HTML server controls or Web server controls.This paper focuses on a series of controls that stand out from the rest—.Figure 1: Test Application in Use The Code The code is very simple and does not require much of an explanation.All that is done is to split the date string up into month, day, and year, and then to attempt to create a date time value from those parts. Regex class for validate any input string for any specific format. Set Error(tb App1, "This is not a valid date; Enter in this format ('M/d/yyyy' or 'M/d/yy')") End If Else Error Provider1. Now I need to validate the date field, I need the dates entered to have this format: dd/mm/yyyy I'm doing: Private Sub txt My Text_Validate(Index As Integer, Cancel As Boolean) If Is Date(Format$(txt My Text(9). Set Focus Msg Box "Please enter a valid date with this format: dd/mm/yyyy." End If End Sub But this code is not working.