??怎样控制textBoxs中录入的数据?? c/s

csharpbase 2004-10-25 07:44:03
1.在身份证号码录入的时候,保证为15位或者18位的阿拉伯数字
2.保证Email的正确录入
3.怎么实现在textBoxs中录入的数据为字符串首必须为英文,后面的必须为英文或者阿拉伯数字,且不能为特殊字符?

这里我指的是Windows 应用程序开发,不是B/S模式的.

三个问题,这里先感谢各位了?
...全文
137 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
csharpbase 2004-10-28
  • 打赏
  • 举报
回复
up
csharpbase 2004-10-26
  • 打赏
  • 举报
回复
up
csharpbase 2004-10-25
  • 打赏
  • 举报
回复
to:shuker(我是一只小花猪) 先谢谢你了,不过我得研究一下!
shuker 2004-10-25
  • 打赏
  • 举报
回复
public class clsStrictedTextBox : System.Windows.Forms.TextBox
{
private string m_strOriginal;
private string m_strCharSet;
private string m_strErrorMessage;
private bool m_bRemoveMsg;
private bool m_bCurrencyMode;
private bool m_bRemoveValueChanged;
private System.Globalization.CultureInfo m_ci;

// true for 可以输入的值必须在charset中, false for 可以输入的值一个都不能出现在charset中
private bool m_bIsInCharSet;

public clsStrictedTextBox()
{
this.m_ci = new System.Globalization.CultureInfo("zh-CN");
this.m_bRemoveMsg = false;
this.m_bCurrencyMode = false;
this.m_bRemoveValueChanged = false;
this.m_strOriginal = "";
this.m_bIsInCharSet = true;
this.m_strCharSet = "";
this.m_strErrorMessage = "";
this.TextChanged += new System.EventHandler(this.OnTextChanged);
this.Leave += new System.EventHandler(this.OnTextBoxLeave);
this.Enter += new System.EventHandler(this.OnTextBoxEnter);
}

/// <summary>
/// 这个函数用来设置字符集和标志
/// </summary>
/// <param name="strCharSet"></param>
/// <param name="bIsIn"></param>
public void SetCharSet(string strCharSet, bool bIsIn)
{
this.m_strCharSet = strCharSet;
this.m_bIsInCharSet = bIsIn;
}

public void SetErrorMessage(string strErrorMessage)
{
this.m_strErrorMessage = strErrorMessage;
}

public void RemoveHook(bool bRemove)
{
this.m_bRemoveMsg = bRemove;
}

public void SetCurrencyMode(string strErrorMessage)
{
this.m_bCurrencyMode = true;
this.m_strCharSet = "0123456789.";
this.m_bIsInCharSet = true;
this.m_strErrorMessage = strErrorMessage;
this.m_bRemoveValueChanged = true;
}

private void ShowErrorMessage()
{
if(this.m_strErrorMessage.Trim ().Length != 0)
System.Windows .Forms .MessageBox.Show (this.m_strErrorMessage);
}

private void OnTextChanged(object sender, System.EventArgs e)
{
if(this.m_bRemoveMsg || this.m_bRemoveValueChanged)
return;

if(this.m_strCharSet.Length == 0)
return;

bool bFind = false;

foreach(char c in this.Text)
{
if(((this.m_bIsInCharSet == true) && (m_strCharSet.IndexOf(c, 0)<0)) ||
((this.m_bIsInCharSet == false) && (m_strCharSet.IndexOf(c, 0)>=0)))
{
bFind = true;
break;
}
}

if(bFind == true)
{
int temp = this.SelectionStart;
this.Text = this.m_strOriginal;
this.SelectionStart = (temp-1)>=0 ? temp-1 : 0;
if(this.m_bCurrencyMode == false)
this.ShowErrorMessage ();
}
else
this.m_strOriginal = this.Text;
}

private void OnTextBoxEnter(object sender, System.EventArgs e)
{
if(this.m_bRemoveMsg || (this.m_bCurrencyMode == false) || (this.Text.Trim().Length == 0))
return;

try
{
double dCurrency = double.Parse(this.Text.Trim(),System.Globalization.NumberStyles.Currency, this.m_ci);

this.Text = dCurrency.ToString("F");

this.m_bRemoveValueChanged = false;
}
catch(Exception)
{
this.Focus();
this.ShowErrorMessage();
}
}

private void OnTextBoxLeave(object sender, System.EventArgs e)
{
if(this.m_bRemoveMsg || (this.m_bCurrencyMode == false))
return;

if(this.Text.Trim().Length == 0)
{
this.Text = "0";
}

try
{
double dCurrency = double.Parse(this.Text.Trim());

this.m_bRemoveValueChanged = true;

this.Text = dCurrency.ToString("C", this.m_ci);
}
catch(Exception)
{
this.m_bRemoveMsg = true;
this.Focus();

this.ShowErrorMessage();
this.m_bRemoveMsg = false;
}
}
}
shuker 2004-10-25
  • 打赏
  • 举报
回复
给你一段代码参考一下
csharpbase 2004-10-25
  • 打赏
  • 举报
回复
首先对hglai(hglai)和CHONGLOU(重楼)的关注表示感谢!

但本人对正则表达式不熟悉

请问各位能不能给一个正则表达式,让我试试??

先感谢了!
CHONGLOU 2004-10-25
  • 打赏
  • 举报
回复
算法问题,不算难,再想想。
hglai 2004-10-25
  • 打赏
  • 举报
回复
1.在身份证号码录入的时候,保证为15位或者18位的阿拉伯数字
用javascript和c#都可以实现
javascript用text1.value.lenght()!=15 ||text1.value.length()!=18{}
c用length,和java差不多


2.保证Email的正确录入
用个验证函数,或者用正则表达试

3.怎么实现在textBoxs中录入的数据为字符串首必须为英文,后面的必须为英文或者阿拉伯数字,且不能为特殊字符?
通用,正则表达式
讲解后台系统的发布、后台功能演示、用户功能演示主要功能模块,分网站管理员和普通用户。 网站管理员功能如下:1:系统设置,设置网站名称2:公司信息设置,设置关于我们、联系我们、加入我们、法律声明3:资讯心管理:录入、修改、查看、删除;4:资讯数据:查看信息浏览记录、查看信息收藏数据、查看信息评论数据5:产品心管理:录入、修改、查看、删除;6:产品数据:查看信息浏览记录、查看信息收藏数据、查看信息评论数据7:案例心管理:录入、修改、查看、删除;8:案例数据:查看信息浏览记录、查看信息收藏数据、查看信息评论数据9:会员管理:查看注册的会员、支持删除功能10:首页轮播图设置:支持随时修改11:留言列表:查看用户留言信息、支持删除 用户功能如下:1:用户注册、用户登录2:资讯:查看所有资讯、收藏资讯、发起评论3:产品:查看所有产品、收藏产品、发起评论4、案例:查看所有案例、收藏案例、发起评论5:支持查询公司的所有产品6:支持给公司管理员留言7:支持修改会员信息8:支持修改密码、退出登录9:支持查看资讯的浏览记录、收藏记录、评论记录10:支持查看产品的浏览记录、收藏记录、评论记录11:支持查看案例的浏览记录、收藏记录、评论记录

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧