Hi tsakumar81,
Use the ISNUMERIC function.
Refer below example.
Stored Procdure
CREATE PROCEDURE ValidateIsNumber
@RequestAmount VARCHAR(21)
As
BEGIN
IF ISNUMERIC(@RequestAmount) = 0
BEGIN
SELECT 0 --INVALID
END
ELSE
BEGIN
SELECT 1 --VALID
END
END
HTML
<asp:TextBox ID="txtNumber" runat="server" />
<asp:Button Text="Validate" runat="server" OnClick="OnValidate" />
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
VB.Net
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Code
C#
protected void OnValidate(object sender, EventArgs e)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string spName = "ValidateIsNumber";
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand(spName, con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@RequestAmount", txtNumber.Text);
con.Open();
bool isNumeric = Convert.ToBoolean(cmd.ExecuteScalar());
con.Close();
if (!isNumeric)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('Invalid number.')", true);
}
}
}
}
VB.Net
Protected Sub OnValidate(sender As Object, e As EventArgs)
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim spName As String = "ValidateIsNumber"
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand(spName, con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@RequestAmount", txtNumber.Text)
con.Open()
Dim isNumeric As Boolean = Convert.ToBoolean(cmd.ExecuteScalar())
con.Close()
If Not isNumeric Then
ClientScript.RegisterClientScriptBlock(Me.GetType(), "", "alert('Invalid number.')", True)
End If
End Using
End Using
End Sub
Screenshot
