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.Create a class of Regular Expressions for validating TextBox text in ASP.Net<p>Please refer this code.</p> <p>&nbsp;<span style="text-decoration: underline;">HTML</span></p> <pre class="brush: html">&lt;asp:TextBox ID=&#34;txtNumber&#34; runat=&#34;server&#34; /&gt; &lt;asp:Button Text=&#34;Validate Number&#34; runat=&#34;server&#34; OnClick=&#34;ValidateNumeric&#34; /&gt;</pre> <p>&nbsp;<span style="text-decoration: underline;">Namespaces</span></p> <pre class="brush: csharp">using System.Text.RegularExpressions;</pre> <p>&nbsp;<span style="text-decoration: underline;">C#</span></p> <pre class="brush: csharp">private bool ValidateNumeric(string text) { Regex test = new Regex(&#34;^[0-9]*$&#34;); return test.IsMatch(text); } protected void ValidateNumeric(object sender, EventArgs e) { bool b = ValidateNumeric(this.txtNumber.Text.Trim()); ClientScript.RegisterStartupScript(this.GetType(), &#34;alert&#34;, &#34;alert(&#39;Validation &#34; + b + &#34;&#39;)&#34;, true); }</pre> <p>Using Class</p> <pre class="brush: csharp">class MyValidationClass { public bool ValidateNumeric(string text) { Regex test = new Regex(&#34;^[0-9]*$&#34;); return test.IsMatch(text); } } protected void ValidateNumeric(object sender, EventArgs e) { MyValidationClass val = new MyValidationClass(); bool b = val.ValidateNumeric(this.txtNumber.Text.Trim()); ClientScript.RegisterStartupScript(this.GetType(), &#34;alert&#34;, &#34;alert(&#39;Validation &#34; + b + &#34;&#39;)&#34;, true); }</pre> <p>Similarly you can do other validations.</p>https://www.aspforums.net:443/Threads/665265/Create-a-class-of-Regular-Expressions-for-validating-TextBox-text-in-ASPNet/https://www.aspforums.net:443/Threads/665265/Create-a-class-of-Regular-Expressions-for-validating-TextBox-text-in-ASPNet/Fri, 14 Nov 2014 03:10:57 GMT