33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ModelBasic
|
|
{
|
|
public class Judge
|
|
{
|
|
|
|
/// <summary>
|
|
/// 判断字符串是否是int/double
|
|
/// </summary>
|
|
public static bool IsIntOrDouble(string strNumber)
|
|
{
|
|
var objNotNumberPattern = new Regex("[^0-9.-]");
|
|
var objTwoDotPattern = new Regex("[0-9]*[.][0-9]*[.][0-9]*");
|
|
var objTwoMinusPattern = new Regex("[0-9]*[-][0-9]*[-][0-9]*");
|
|
const string strValidRealPattern = "^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$";
|
|
const string strValidIntegerPattern = "^([-]|[0-9])[0-9]*$";
|
|
var objNumberPattern = new Regex("(" + strValidRealPattern + ")|(" + strValidIntegerPattern + ")");
|
|
return !objNotNumberPattern.IsMatch(strNumber) &&
|
|
!objTwoDotPattern.IsMatch(strNumber) &&
|
|
!objTwoMinusPattern.IsMatch(strNumber) &&
|
|
objNumberPattern.IsMatch(strNumber);
|
|
}
|
|
|
|
|
|
}
|
|
}
|