Chinaunix首页 | 论坛 | 博客
  • 博客访问: 197000
  • 博文数量: 7
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 600
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-02 11:24
文章分类

全部博文(7)

文章存档

2008年(7)

我的朋友

分类:

2008-03-03 17:55:01

1、string   pat=@ "[\u4e00-\u9fa5] ";
Regex   rg=new   Regex(pat);
Match   mh=rg.Match(textBox1.Text);
if(mh.Success)
{
  //是汉字
}
2、function   fucCheckNUM(NUM)
{
var   i,j,strTemp;
strTemp= "0123456789. ";
if   (   NUM.length==   0)
return   0
for   (i=0;i {
j=strTemp.indexOf(NUM.charAt(i));  
if   (j==-1)
{
//说明有字符不是数字
return   0;
}
}
//说明是数字
return   1;
}
 
正解:
System.Text.RegularExpressions.Regex   reg1   =   new   System.Text.RegularExpressions.Regex(@ "^[-]?\d+[.]?\d*$ ");
                   
if(reg1.IsMatch(str))
{
//数字
}  
else
{
//非数字
}
 
private   bool   isNum(string   keyChar)
        {
                int   i   =   0;
                char   c;
                for   (i   =   0;   i   <   keyChar.Length;   i++)
                {
                        c   =   keyChar[i];
                        if   (!(c   > =   48   &&   c   <=   57))
                        {
                                return   false;
                        }
                }
                return   true;
        }

判断是否只含小数点和数字
        private   bool   isDecimalNum(string   keyChar)
        {
                int   i   =   0;
                char   c;
                for   (i   =   0;   i   <   keyChar.Length;   i++)
                {
                        c   =   keyChar[i];
                        if   (!(c   > =   48   &&   c   <=   57   ||   c   ==   46))
                        {
                                return   false;
                        }
                }
                return   true;
        }


//判断是否只含数字
        private   bool   isNum(string   str)
        {
                Regex   r   =   new   Regex( "^[0-9]*$ ");
                Match   m   =   r.Match(str);
                if   (m.Success)
                {
                        return   true;
                }
                else  
                {
                        return   false;
                }
        }
阅读(1019) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:查询记录行动态累加

给主人留下些什么吧!~~