社区
C#
帖子详情
??怎样控制textBoxs中录入的数据?? c/s
csharpbase
2004-10-25 07:44:03
1.在身份证号码录入的时候,保证为15位或者18位的阿拉伯数字
2.保证Email的正确录入
3.怎么实现在textBoxs中录入的数据为字符串首必须为英文,后面的必须为英文或者阿拉伯数字,且不能为特殊字符?
这里我指的是Windows 应用程序开发,不是B/S模式的.
三个问题,这里先感谢各位了?
...全文
144
8
打赏
收藏
??怎样控制textBoxs中录入的数据?? c/s
1.在身份证号码录入的时候,保证为15位或者18位的阿拉伯数字 2.保证Email的正确录入 3.怎么实现在textBoxs中录入的数据为字符串首必须为英文,后面的必须为英文或者阿拉伯数字,且不能为特殊字符? 这里我指的是Windows 应用程序开发,不是B/S模式的. 三个问题,这里先感谢各位了?
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用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中录入的数据为字符串首必须为英文,后面的必须为英文或者阿拉伯数字,且不能为特殊字符?
通用,正则表达式
求助:scratch按下空入多次
录入
数据
问题该怎么解决?
求助:scratch按下空入多次
录入
数据
问题该怎么解决?
CASS
数据
属性转入ArcGis终极战略(AutoCAD插件实现)
在AutoCAD或者CASS
数据
向ArcGis
数据
转换过程
中
,您是否还在为自己
录入
的属性无法转出而烦恼?是否仍因转出的字段名称、类型、长度、缺省值不符合要求而苦闷?是否还在因规范对要素属性结构的定义变化无常而纠结? 不用担心,这里给出解决以上问题的终极战略和方案。
学生宿舍管理系统 学生宿舍管理系统
【题目】学生宿舍管理系统 考查点:线性结构、文件操作 注意:必须使用文件存储
数据
,不得使用
数据
库管理系统。 任务:通过此系统可以实现如下功能:
录入
: 可以
录入
宿舍情况,包括宿舍号、可容纳学生数、已容纳学生数、男生/女生宿舍等信息; 可以
录入
学生住宿情况,包括学号、姓名、性别、宿舍号等信息。 其他信息可以自行设计。 分配宿舍:为每一个学生分配入一个未住满的宿舍。能否提供一个智能分配算法?推荐选择?批量分配?鼓励创新。 调换宿舍:实现一个学生调换宿舍操作以及两个同性学生互换宿
大酒店住宿管理和顺丰速递
数据
打印-易语言
功能: ? 设计打印模版 ? 选择打印模板 ?
录入
单据信息 ? 预览 打印单据信息 ? 打印 单据 ? 保存 单据 ? 记录 单据号(快递) ? 导入快递单批量打印
自动将Excel
数据
录入
网页/ERP/CRM
如何以全自动方式将大量Excel
数据
批量填入网页,ERP,CRM等几乎所有系统(支持Excel
中
的图片),全程只需几步。 1.准备环境 下载GoBot,直接安装就行; 地址:https://dgo.ink/crm/dl/?shareId=367561 手册:https://d.dgo.ink/doc/GoBot_Pro_1.0.pdf 2.准备Excel
数据
参考截图制作Excel
数据
(保持结构一致,无需完全相同)。 3.确定
录入
目标 参考...
C#
111,097
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章