c# - 在 C# 中,如何查看帐户中的第一个字符是否为特定值?
问题描述
我有一个包含 15 位帐号的字符串。第一个数字不能是 0、1、8 或 9。我想说的是:
public bool ValidateAccountNumber(string Accountnumber )
{
char[] Invalidboro = new char[] { '0', '1', '8', '9'};
bool returnValue = true;
if (Accountnumber.Length != 15 || Accountnumber.Substring(1, 1).Contains(Invalidboro))
{
returnValue = false;
}
return returnValue;
}
我是 C# 新手,不知道该怎么做。
解决方案
正则表达式
public bool ValidateAccountNumber(string Accountnumber)
{
return Accountnumber != null && Regex.IsMatch(Accountnumber, "^[2-7][0-9]{14}$");
}
推荐阅读
- java - 测试 Spring Boot 命令行应用程序
- ios - Firebase 动态链接应用关联文件更新
- apache-spark - 将数据从火花工作者返回给驱动程序的最佳方式
- ffmpeg - FFmpeg:如何打开名称中带有撇号的文件?
- sql-server - Python3 pypyodbc SQL Server 调用存储过程失败
- mysql - 泛化一个 sql 查询以适应完整和增量提取
- python - 在 python 中使用 SQLite3 时出现 TypeError
- python - 在 anaconda 中克隆基础环境
- python - 无法 pip install eel 。- 退出状态为 1 的命令出错:python setup.py egg_info 检查日志以获取完整的命令输出
- ruby - Ruby AWS 开发工具包错误。module_inheritable_attributes.rb 中的值 nil