| Author: kingfisher 12 May 2008 | Member Level: Silver Points : 2 |
CHNumeric = IsNumeric(txtbox1.Text) If CHNumeric = False Then MsgBox("Enter numeric value Only", MsgBoxStyle.Exclamation, Application.ProductName) txtbox1.Focus() Exit Sub End If
'----------> I have used an inbuilt function "IsNumeric" which returns boolean value after checking for numeric values
|
| Author: santhoshkumar 23 May 2008 | Member Level: Gold Points : 2 |
By default the textbox value is string right, then how can v check isNumeric for string value.
|
| Author: ranipriya 04 Jun 2008 | Member Level: Gold Points : 2 |
Santhosh, No need of complex code use only simple code
Check this vb.net code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Not IsNumeric(t1.Text) Then MsgBox("Enter numeric value", MsgBoxStyle.Critical) Else MsgBox("You entered " & t1.Text, MsgBoxStyle.Information) End If End Sub
Function IsNumeric is there..
Public Function IsNumeric(ByVal Expression As Object) As Boolean Member of: Microsoft.VisualBasic.Information
Summary: Returns a Boolean value indicating whether an expression can be evaluated as a number.
OK....
|
| Author: santhoshkumar 04 Jun 2008 | Member Level: Gold Points : 0 |
ok. thank you ranipriya
|
| Author: sivangari 11 Jun 2008 | Member Level: Gold Points : 2 |
protected void Button1_Click(object sender, EventArgs e) { string str = TextBox1.Text; string str1 = TextBox4.Text; int result = 0; if( (int.TryParse(str, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.CurrentInfo, out result)) && (int.TryParse(str1, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.CurrentInfo, out result))) { Label1.Text = "Number"; } else { Label1.Text = "string"; }
|
| Author: KR 12 Dec 2008 | Member Level: Gold Points : 1 |
Hi, Find the below code,
private void button1_Click(object sender, EventArgs e) { int s; if (!int.TryParse(textBox1.Text, out s)) { MessageBox.Show("Charactes not allowed"); } }
|
| Author: Abhinav Misra 14 Dec 2008 | Member Level: Silver Points : 1 |
dont u think that it is better to use
java script or compare validation control and set its property for type check
|