using System;
using System.Data;
using System.Text.RegularExpressions;
class Class1{
static void Main(string[] args){
string IsNotNum = "111west";
string IsNum = " +111 ";
string IsFloat = " 23.11 ";
string IsExp = " +23 e+11 ";
Console.WriteLine(IsUnsignedIntegerRegEx(IsNum)); // True
Console.WriteLine(IsUnsignedIntegerRegEx(IsNotNum)); // False
Console.WriteLine(IsUnsignedIntegerRegEx(IsFloat)); // False
Console.WriteLine(IsUnsignedIntegerRegEx(IsExp)); // False
}
public static bool IsUnsignedIntegerRegEx(string str)
{
str = str.Trim();
return (Regex.IsMatch(str, @"^\+?\d+$"));
}
}
|