Home » 2013 » January » 17

Archive for January 17, 2013

Validate date in code behind with regex – VB.NET

Code behind ‘define public var Protected StartDate As String Protected EndDate As String ‘define other var Dim sDate = Request.Form(“startDateTbx”) Dim eDate = Request.Form(“endDateTbx”) Dim r As Regex r = New Regex(“^(0[1-9]|[1-9]|1[012])/(0[1-9]|[1-9]|[12][0-9]|3[01])/20\d\d$”) ‘run validation If sDate = “” Then startDateLbl.Text = “Required” ElseIf Not r.Match(sDate).Success Then startDateLbl.Text = “Invalid date. Use mm/dd/yyyy.” Else startDateLbl.Text = […]