Asp C# Regex for numeric characters only
In this article I will show you how to accept only numeric characters in asp .net c# using regex. Here is a label which contains alphanumric and special characters.
<asp:label text= "a<b,c>d.e?f'g;H;i|j]k[l{m}n+o=p-q-r)s(t*u&v^%w$x#y@z!a~b`c123456789" id= "lblValue" runat= "server" > </asp:label>
|
Now to use Regex in asp .net we need to add Namespace
using System.Text.RegularExpressions;
|
Using asp c# code behind
Regex reg = new Regex( @"[^0-9]" );
string str = reg.Replace(lblValue.Text, "-" );
Response.Write(str);
|
Output :
