.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

validate numeric value with decimal point

Posted By: jagdish     Posted Date: January 28, 2010    Points:2   Category :Windows Application
in window appication using C#, in datagrid cell I want validate numeric value with decimal point between 0-9 and only one dot '.'

Responses
Author: Lalij Mer             
Posted Date: January 29, 2010     Points: 5   

show this code sample

private bool IsValidNumber(string number)
{
int position = number.IndexOf(".");

if (position != -1)
{
int decdigits = number.Substring(position + 1, number.Length - number.IndexOf('.') - 1).Length;
if (decdigits == 2)
{
return true;
}
else
{
return false;
}
}
return false;
}


And you could call this as

private void button1_Click(object sender, EventArgs e)
{
bool val = IsValidNumber(textBox1.Text);
if (val == false)
{
MessageBox.Show("Invalid number");
textBox1.Focus();
}
}


Please Check my answer if you help....
Thank You...

Lalit.
Author: AK             
Posted Date: January 29, 2010     Points: 5   

Check

http://anishstechblog.blogspot.com/2010/01/validate-datagridview-in-windows-forms.html

Author: Prasanti Prusty             
Posted Date: January 29, 2010     Points: 5   

Hi,

Check the links :

http://www.dotnetspark.com/kb/1477-common-function-to-validate-decimal-numbers.aspx
http://www.dotnetspark.com/kb/1251-function-to-validate-number-digits-before.aspx

Regards,
Prasanti


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend