获取源码方式:
第一种:打开微信,搜一搜"别打我女儿的主意"打开微信小程序,找到菜单栏,点击源码,进去就可以获得链接
第二种:可以给本文点赞、好评,然后发邮件到792166417@qq.com,如果有学习资料视频可以分享的话,可以捎带分享给我。
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace IDcard
{
public partial class Card : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Check("360601198801310373"))
{
Response.Write("成功");
}
else
{
Response.Write("失败");
}
}
//加权因子
private static readonly int[] _factors = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 };
//验证位置
private static readonly int[] _codes = { 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 };
/// <summary>
/// 验证是否为身份证号
/// </summary>
/// <param name="idcard">身份证号</param>
/// <returns></returns>
public static bool Check(string idcard)
{
if (idcard.Length == 18)
{
if (ValidBirthday(idcard) && ValidateCode(idcard))
{
return true;
}
}
return false;
}
/// <summary>
/// 验证生日
/// </summary>
/// <param name="idcard">身份证号</param>
/// <returns></returns>
private static bool ValidBirthday(string idcard)
{
string year = idcard.Substring(6, 4);
string month = idcard.Substring(10, 2);
string day = idcard.Substring(12, 2);
DateTime date;
string xdate = year + month + day;
bool result = DateTime.TryParseExact(xdate, "yyyyMMdd", new DateTimeFormatInfo(), DateTimeStyles.AdjustToUniversal, out date);
if (!result)
{
return false;
}
string xmonth = date.Month < 10 ? "0" + date.Month : date.Month.ToString();
string xday = date.Day < 10 ? "0" + date.Day : date.Day.ToString();
if (!date.Year.ToString().Equals(year) || !month.Equals(xmonth) || !day.Equals(xday))
{
return false;
}
return true;
}
/// <summary>
/// 验证身份证规则
/// </summary>
/// <param name="idcard">身份证号</param>
/// <returns></returns>
private static bool ValidateCode(string idcard)
{
int sum = 0;
char[] chars = idcard.ToCharArray();
List<string> list = chars.Select(c => c.ToString()).ToList();
if (list[17] == "x")
{
list[17] = "10";
}
for (int i = 0; i < 17; i++)
{
sum += _factors[i] * Convert.ToInt32(list[i]);
}
//获取验证位置
int position = sum % 11;
if (list[17].Equals(_codes[position].ToString()))
{
return true;
}
return false;
}
}
}