Hopes

Start Here..

 

获取串长度、判断字符串是否非法、input只能选择

private int GetFieldLength(string Field)
{
/*int len=0;
foreach(char ch in Field)
{
len+=sizeof(ch);
}*/
int len = System.Text.Encoding.Default.GetByteCount(Field);
return len;
//return len;
}

private bool IsFieldValid(string field, ref string msg)
{

//\ / : * ? " < >
foreach (char ch in field)
{
if ((ch == '\'' || ch == '"' || ch == '\t' || ch == ':' || ch == '&' || ch == '\\' || ch == '/' || ch == '*' || ch == '?' || ch == '<' || ch == '>'))
{
if (ch == '\'')
{
msg = "存在非法字符" + "\\'";
}
else if (ch == '\\')
{
msg = "存在非法字符" + "\\\\";
}
else
{
msg = "存在非法字符" + ch;
}

return false;
}
}

return true;

}

 <input id="TxBox_Time" runat="server" maxlength="10" readonly="readOnly" name="date" onfocus="setday(this)" style="width: 235px" />



posted on 2012-09-27 10:23 ** 阅读(136) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

公告

你好!

常用链接

留言簿(2)

随笔档案

文章分类

文章档案

新闻档案

相册

收藏夹

C#学习

友情链接

搜索

最新评论

阅读排行榜

评论排行榜