{"id":2434,"date":"2013-01-17T12:46:00","date_gmt":"2013-01-17T16:46:00","guid":{"rendered":"http:\/\/www.iowawebnet.com\/ein\/?p=2434"},"modified":"2013-01-17T12:46:00","modified_gmt":"2013-01-17T16:46:00","slug":"validate-date-in-code-behind-with-regex-vb-net","status":"publish","type":"post","link":"https:\/\/www.iowawebnet.com\/ein\/2013\/01\/validate-date-in-code-behind-with-regex-vb-net\/","title":{"rendered":"Validate date in code behind with regex &#8211; VB.NET"},"content":{"rendered":"<pre>\r\nCode behind\r\n<code>\r\n'define public var\r\nProtected StartDate As String\r\nProtected EndDate As String\r\n\r\n'define other var\r\nDim sDate = Request.Form(\"startDateTbx\")\r\nDim eDate = Request.Form(\"endDateTbx\")\r\nDim r As Regex \r\nr = New Regex(\"^(0[1-9]|[1-9]|1[012])\/(0[1-9]|[1-9]|[12][0-9]|3[01])\/20\\d\\d$\") \r\n\r\n'run validation\r\nIf sDate = \"\" Then\r\n     startDateLbl.Text = \"Required\"\r\n ElseIf Not r.Match(sDate).Success Then\r\n    startDateLbl.Text = \"Invalid date. Use mm\/dd\/yyyy.\"\r\n Else\r\n    startDateLbl.Text = \"\"\r\nEnd If\r\n\r\nIf eDate <> \"\" And Not r.Match(eDate).Success Then\r\n   endDateLbl.Text = \"Invalid date. Use mm\/dd\/yyyy.\"\r\nElse\r\n   endDateLbl.Text = \"\"\r\nEnd If\r\n\r\nStartDate = sDate\r\n EndDate = eDate\r\n<\/code>\r\n\r\nMarkup page\r\n<code>\r\n&lt;%=StartDate%>\r\n&lt;%=EndDate%>\r\n<\/code>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Code behind &#8216;define public var Protected StartDate As String Protected EndDate As String &#8216;define other var Dim sDate = Request.Form(&#8220;startDateTbx&#8221;) Dim eDate = Request.Form(&#8220;endDateTbx&#8221;) Dim r As Regex r = New Regex(&#8220;^(0[1-9]|[1-9]|1[012])\/(0[1-9]|[1-9]|[12][0-9]|3[01])\/20\\d\\d$&#8221;) &#8216;run validation If sDate = &#8220;&#8221; Then startDateLbl.Text = &#8220;Required&#8221; ElseIf Not r.Match(sDate).Success Then startDateLbl.Text = &#8220;Invalid date. Use mm\/dd\/yyyy.&#8221; Else startDateLbl.Text = [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85,17,16,56,84],"tags":[19,144,27,21],"class_list":["post-2434","post","type-post","status-publish","format-standard","hentry","category-net-4-0","category-applications","category-net","category-validation-controls","category-vs2010","tag-asp-net","tag-controls","tag-form-validation","tag-visual-studio"],"_links":{"self":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2434"}],"collection":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/comments?post=2434"}],"version-history":[{"count":7,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2434\/revisions"}],"predecessor-version":[{"id":2441,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/posts\/2434\/revisions\/2441"}],"wp:attachment":[{"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/media?parent=2434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/categories?post=2434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.iowawebnet.com\/ein\/wp-json\/wp\/v2\/tags?post=2434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}