[Csharp]
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Text. RegularExpressions;
Namespace shop
{
Public class IsNum
{
/// <Summary>
/// Determine whether it is a number
/// </Summary>
/// <Param name = "strNumber"> string to be judged </param>
/// <Returns> </returns>
Public bool IsNumber (String strNumber)
{
Regex objNotNumberPattern = new Regex ("[^ 0-9.-]");
Regex objTwoDotPattern = new Regex ("[0-9] * [.] [0-9] * [.] [0-9] *");
Regex objTwoMinusPattern = new Regex ("[0-9] * [-] [0-9] * [-] [0-9] *");
String strValidRealPattern = "^ ([-] | [.] | [-.] | [0-9]) [0-9] * [.] * [0-9] + $ ";
String strValidIntegerPattern = "^ ([-] | [0-9]) [0-9] * $ ";
Regex objNumberPattern = new Regex ("(" + strValidRealPattern + ") | (" + strValidIntegerPattern + ")");
Return! ObjNotNumberPattern. IsMatch (strNumber )&&
! ObjTwoDotPattern. IsMatch (strNumber )&&
! ObjTwoMinusPattern. IsMatch (strNumber )&&
ObjNumberPattern. IsMatch (strNumber );
}
}
}
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Text. RegularExpressions;
Namespace shop
{
Public class IsNum
{
/// <Summary>
/// Determine whether it is a number
/// </Summary>
/// <Param name = "strNumber"> string to be judged </param>
/// <Returns> </returns>
Public bool IsNumber (String strNumber)
{
Regex objNotNumberPattern = new Regex ("[^ 0-9.-]");
Regex objTwoDotPattern = new Regex ("[0-9] * [.] [0-9] * [.] [0-9] *");
Regex objTwoMinusPattern = new Regex ("[0-9] * [-] [0-9] * [-] [0-9] *");
String strValidRealPattern = "^ ([-] | [.] | [-.] | [0-9]) [0-9] * [.] * [0-9] + $ ";
String strValidIntegerPattern = "^ ([-] | [0-9]) [0-9] * $ ";
Regex objNumberPattern = new Regex ("(" + strValidRealPattern + ") | (" + strValidIntegerPattern + ")");
Return! ObjNotNumberPattern. IsMatch (strNumber )&&
! ObjTwoDotPattern. IsMatch (strNumber )&&
! ObjTwoMinusPattern. IsMatch (strNumber )&&
ObjNumberPattern. IsMatch (strNumber );
}
}
}