c#判断判断字符串是否由数字构成

调用方法

private bool isNoNumber(string bankAccount)
{

判断字符串中是否有空格
if (bankAccount.IndexOf(" ") >= 0)
{

去除字符串中空格
string trim = Regex.Replace(bankAccount, @"\s", "");
if (Regex.IsMatch(trim, @"^\d+$"))
{
return false;--这里是数字组成,但我返回的是false
}
else
{
return true;--不是数字组成,我返回的true
}
}
else {
if (Regex.IsMatch(bankAccount, @"^\d+$"))
{
return false;
}
else
{
return true;
}
}

}

 1 private bool isNoNumber(string bankAccount)
 2         {
 3             if (bankAccount.IndexOf(" ") >= 0)
 4             {
 5                 string trim = Regex.Replace(bankAccount, @"\s", "");
 6                 if (Regex.IsMatch(trim, @"^\d+$"))
 7                 {
 8                     return false;
 9                 }
10                 else
11                 {
12                     return true;
13                 }
14             }
15             else {
16                 if (Regex.IsMatch(bankAccount, @"^\d+$"))
17                 {
18                     return false;
19                 }
20                 else
21                 {
22                     return true;
23                 }
24             }
25 
26         }

猜你喜欢

转载自www.cnblogs.com/BottleKing/p/9149440.html