C# Numeric Validation

C# does n’t have any built-in function to validate Numeric Data Type. you can write a simple function to validate Number using TryParse Method of Double Data Type. This will return true or false is subject to the argument is Numeric or not.

public static class InputValidator
 public Boolean validateNumber(string amount)
  Boolean numberValidationResult;
  Double returnNumber;
  numberValidationResult = Double.TryParse(amount, System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out returnNumber);  
  return numberValidationResult;

Use it like

if (InputValidator.validateNumber(amountTextBox.Text) == true)
   // Do something
  // Do something

A Rahim Khan

  1. it is helpful ..! but i need a code for reading excel using php

    • Jai Sharma
    • December 28th, 2010

    Can you tell me how can I import data from excel file which contain data in both Hindi and English to MS SQL 2005 table. I am able to do it in english alone but when I try to import data in Hindi as well it gives me english characters in place of hindi characters in my table.

    • you can convert your hindi/english data to unicode and save it in Database. Again, you can retrieve and format it to your expected format. I have done this kind of job from front end, I think this can be done using SQL Server as well. You just have to look around.


  2. Hi,

    This is Biswabhusan from CodeRND.com. This is a Technical Search Enginee. I want to discuss few related to this. Please feel free to respond me on my private email id.

    Thank you

    Waiting for your kind response.


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: