if you use web based then use below function
public bool IsAlpha(string input)
{
return Regex.IsMatch(input, "^[a-zA-Z]+$");
}
public bool IsAlphaNumeric(string input)
{
return Regex.IsMatch(input, "^[a-zA-Z0-9]+$");
}
public bool IsAlphaNumericWithUnderscore(string input)
{
return Regex.IsMatch(input, "^[a-zA-Z0-9_]+$");
}
or if you use Web development then use java script
script type="text/javascript" language="javascript">
function validateNumbersOnly(e) {
var unicode = e.charCode ? e.charCode : e.keyCode;
if ((unicode == 8) || (unicode == 9) || (unicode > 47 && unicode < 58)) {
return true;
}
else {
window.alert("This field accepts only Numbers");
return false;
}
}
</script>
on page use below code
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" Display="None" ErrorMessage="Accepts only numbers." ControlToValidate="TextBox1" ValidationExpression=""^[0-9]*$" Text="*"></asp:RegularExpressionValidator>