ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Image URL validation using Regular Expressions in ASP.Net<p>Hi&nbsp;<a href="mailto:v@run,">v@run,</a></p> <p>Refer below code. Use&nbsp;RegularExpressions to validate the url.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: csharp">&lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtImageUrl&#34; Text=&#34;https://i.imgur.com/6LLBMoM.jpg&#34; /&gt; &lt;asp:Button Text=&#34;Validate&#34; runat=&#34;server&#34; OnClick=&#34;Validate&#34; /&gt;</pre> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">protected void Validate(object sender, EventArgs e) { if (!System.Text.RegularExpressions.Regex.IsMatch(txtImageUrl.Text, @&#34;(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))&#34;)) { ClientScript.RegisterClientScriptBlock(this.GetType(), &#34;&#34;, &#34;alert(&#39;Url is invalid.&#39;)&#34;, true); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), &#34;&#34;, &#34;alert(&#39;Url is valid.&#39;)&#34;, true); } }</pre> <p><strong><span style="text-decoration: underline;">VB.Net</span></strong></p> <pre class="brush: vb">Protected Sub Validate(ByVal sender As Object, ByVal e As EventArgs) If Not System.Text.RegularExpressions.Regex.IsMatch(txtImageUrl.Text, &#34;(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))&#34;) Then ClientScript.RegisterClientScriptBlock(Me.[GetType](), &#34;&#34;, &#34;alert(&#39;Url is invalid.&#39;)&#34;, True) Else ClientScript.RegisterClientScriptBlock(Me.[GetType](), &#34;&#34;, &#34;alert(&#39;Url is valid.&#39;)&#34;, True) End If End Sub</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <p>https://i.imgur.com/6LLBMoM.jpg&nbsp;- Valid Url</p> <p>https://i.imgur.com/6LLBMoM.aspx&nbsp;- Invalid url</p>https://www.aspforums.net:443/Threads/365074/Image-URL-validation-using-Regular-Expressions-in-ASPNet/https://www.aspforums.net:443/Threads/365074/Image-URL-validation-using-Regular-Expressions-in-ASPNet/Mon, 29 Oct 2018 03:56:35 GMT