资源简介
自定义的一个TextBox控件,包含限制只能输入数字、验证邮箱、电话、手机、身份证号码、邮件地址等功能,提供源码,蛮适合初学者学习和使用的~~

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.Regularexpressions;
using TextBoxM;
namespace TextBoxM
{
//创建一个枚举类
public enum AllowType
{
All
Num
UserName
Psw
Email
IDcard
MobliePhone
Tel
}
public class AgiaTxetBox:TextBox
{
private AllowType _allowType = AllowType.All;
public AllowType Type
{
get { return _allowType; }
set { _allowType = value; }
}
//string UserName = “^(?!_)(?!.*?_$)[a-zA-Z0-9_\u4e00-\u9fa5]+$“;//限制字母、数字和下划线,下划线不能放在最末
///
/// 身份证验证方法
///
///
///
public static bool IsValidIdcard(string Id)
{
if (Id.Length != 18)
{
return false;
}
//数字验证
long n = 0;
if (long.TryParse(Id.Remove(17) out n) == false || n < Math.Pow(10 16) || long.TryParse(Id.Replace(‘x‘ ‘0‘).Replace(‘X‘ ‘0‘) out n) == false)
{
return false;
}
//省份验证
string address = “11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91“;
if (address.IndexOf(Id.Remove(2)) == -1)
{
return false;
}
//生日验证
string birth = Id.Substring(6 8).Insert(6 “-“).Insert(4 “-“);
DateTime time = new DateTime();
if (DateTime.TryParse(birth out time) == false)
{
return false;
}
//校验码验证
string[] arrVarifyCode = (“10x98765432“).Split(‘‘);
string[] Wi = (“7910584216379105842“).Split(‘‘);
char[] Ai = Id.Remove(17).ToCharArray();
int sum = 0;
for (int i = 0; i < 17; i++)
{
sum += int.Parse(Wi[i]) * int.Parse(Ai[i].ToString());
}
int y = -1;
Math.DivRem(sum 11 out y);
if (arrVarifyCode[y] != Id.Substring(17 1).ToLower())
{
return false;
}
return true;
}
///
/// 重写KeyPress事件
///
///
protected override void onkeypress(KeyPressEventArgs e)
{
e.Handled = true;
if (_allowType == AllowType.Email || _allowType == AllowType.UserName || _allowType == AllowType.All || _allowType == AllowType.Psw)
{
e.Handled = false;
}
//限制只能输入数字
if
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 920 2011-11-25 14:33 TextBoxW.sln
..A..H. 12800 2011-11-25 14:37 TextBoxW.suo
文件 2597 2011-11-25 14:32 TextBoxM\AgiaTextBox.csproj
文件 7577 2011-11-25 14:32 TextBoxM\AgiaTxetBox.cs
文件 15872 2011-11-25 14:33 TextBoxM\bin\Debug\TextBoxM.pdb
文件 373 2011-11-25 14:33 TextBoxM\obj\Debug\AgiaTextBox.csproj.FileListAbsolute.txt
文件 951 2011-11-25 14:32 TextBoxM\obj\Debug\TextBoxM.csproj.FileListAbsolute.txt
文件 7680 2011-11-25 14:33 TextBoxM\obj\Debug\TextBoxM.dll
文件 15872 2011-11-25 14:33 TextBoxM\obj\Debug\TextBoxM.pdb
文件 1348 2011-11-20 11:19 TextBoxM\Properties\AssemblyInfo.cs
目录 0 2011-11-25 14:32 TextBoxM\obj\Debug\Refactor
目录 0 2011-11-20 11:19 TextBoxM\obj\Debug\TempPE
目录 0 2011-11-25 14:33 TextBoxM\bin\Debug
目录 0 2011-11-25 14:33 TextBoxM\obj\Debug
目录 0 2011-11-25 14:32 TextBoxM\bin
目录 0 2011-11-20 11:19 TextBoxM\obj
目录 0 2011-11-20 11:19 TextBoxM\Properties
目录 0 2011-11-25 14:33 TextBoxM
----------- --------- ---------- ----- ----
65990 18
相关资源
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
评论
共有 条评论