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.Check if String contains URL using JavaScript<p>Hi <a class="username" rel="chetan"> chetan</a>,</p> <p>Use regular expression to check the statement.</p> <p>Refer below code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <div class="demo_block"> <pre class="brush: html">&lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;script type=&#34;text/javascript&#34;&gt; function CheckUrl() { var text = document.getElementById(&#39;txtStatement&#39;).value; if (new RegExp(&#34;([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?&#34;).test(text)) { alert(&#34;Url is present in this statement&#34;); } else { alert(&#34;Url not is present in this statement&#34;); } } &lt;/script&gt; &lt;input type=&#34;text&#34; id=&#34;txtStatement&#34; style=&#34;width: 450px;&#34; value=&#34;Office 366, Zine Square 6, Business Bay, https://www.Luxuryproperty.Com/&#34; /&gt; &lt;input id=&#34;btnCheck&#34; type=&#34;button&#34; value=&#34;Check Url&#34; onclick=&#34;CheckUrl()&#34; /&gt; &lt;/body&gt; &lt;/html&gt;</pre> </div> <p><a class="demo button orange btn btn-red">Demo</a></p>https://www.aspforums.net:443/Threads/194095/Check-if-String-contains-URL-using-JavaScript/https://www.aspforums.net:443/Threads/194095/Check-if-String-contains-URL-using-JavaScript/Thu, 02 May 2019 04:10:41 GMTCheck if String contains URL using JavaScript<p>i slightly modified your javascript and it worked:</p> <pre class="brush: js">function CheckUrl() { var text = document.getElementById(&#39;&lt;%=addtxt.ClientID%&gt;&#39;).value; if (new RegExp(&#34;([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?&#34;).test(text)) { alert(&#34;Url is not allowed in address field&#34;); return false; }</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/194095/Check-if-String-contains-URL-using-JavaScript/https://www.aspforums.net:443/Threads/194095/Check-if-String-contains-URL-using-JavaScript/Thu, 02 May 2019 06:08:04 GMT