Hi lingers,
Check this example. Now please take its reference and correct your code.
HTML
Enter Number:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
<br />
<asp:Label ID="Label50" runat="server"></asp:Label>
Code
C#
protected void Button1_Click(object sender, EventArgs e)
{
Label50.Text = IsDoubleNaN(TextBox1.Text);
}
public string IsDoubleNaN(string text)
{
if (string.IsNullOrEmpty(text))
{
return "it's not a number";
}
Double num = 0;
bool isDouble = Double.TryParse(text, out num);
return isDouble ? "it's a number" : "it's not a number";
}
VB.Net
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Label50.Text = IsDoubleNaN(TextBox1.Text)
End Sub
Public Function IsDoubleNaN(ByVal text As String) As String
If String.IsNullOrEmpty(text) Then
Return "it's not a number"
End If
Dim num As Double = 0
Dim isDouble As Boolean = Double.TryParse(text, num)
Return If(isDouble, "it's a number", "it's not a number")
End Function
Screenshot
