Language:

IsPositiveNumber

Language: English
Programming Language: C#
Published by: Thomas
Last Update: 5/4/2006
Views: 762

Description

Function to Test for Positive Number both Integer and Real

Code

1 public static bool IsPositiveNumber(string strNumber) { 2 try { 3 Regex objNotPositivePattern=new Regex("[^0-9.]"); 4 Regex objPositivePattern=new Regex("^[.][0-9]+$|[0-9]*[.]*[0-9]+$"); 5 Regex objTwoDotPattern=new Regex("[0-9]*[.][0-9]*[.][0-9]*"); 6 return !objNotPositivePattern.IsMatch(strNumber) && 7 objPositivePattern.IsMatch(strNumber) && 8 !objTwoDotPattern.IsMatch(strNumber); 9 } 10 catch { 11 return false; 12 } 13 } 14

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS