首页 新闻 会员 周边

表單長度的問題

0
悬赏园豆:5 [已解决问题] 解决于 2012-12-20 11:36

問題、 有一個表單textbox 在數據庫中的長度是numeric(5,8)

          那麼此表單的長度要設置為多少呢,並且如何判斷用戶輸入是否有誤呢

 謝謝

 

搞錯了numeric(8,5)

Peter.zhong的主页 Peter.zhong | 初学一级 | 园豆:117
提问于:2012-12-17 19:21
< >
分享
最佳答案
1

长度为5,  小数点后面有8位,不合理啊

收获园豆:3
chenping2008 | 大侠五级 |园豆:9836 | 2012-12-17 20:43

不好意思,弄錯了,是numeric(8,5)

Peter.zhong | 园豆:117 (初学一级) | 2012-12-18 08:32

@Peter.zhong: 这个应该没有一个硬性的规定吧 难道我输入12.3 就不行吗?

http://digitalbush.com/projects/masked-input-plugin/

正则或者是JS来验证都可以。最好是正则来验证,因为正则在JS端和服务器端都可以运行的。

严格的验证

 Regex regex = new Regex("[1-9]{3}.[0-9]{5}");
            string str = "999.5555";
            Console.WriteLine(regex.IsMatch(str));

true

chenping2008 | 园豆:9836 (大侠五级) | 2012-12-18 09:08

@chenping2008: 

 

沒有什麼硬性規定,只要整數位不超過3碼,小數位不超過5碼,小數位也可有可無

搞的吐血。這正則怎麼寫比較好

Peter.zhong | 园豆:117 (初学一级) | 2012-12-18 09:31

@Peter.zhong: 

Regex regex = new Regex("[1-9]{0,3}.[0-9]{0,5}");
            string str = "999.5555";
            Console.WriteLine(regex.IsMatch(str));
             str = "9.5555";
            Console.WriteLine(regex.IsMatch(str));
            str = ".5555";
            Console.WriteLine(regex.IsMatch(str));
            str = "9.5";
            Console.WriteLine(regex.IsMatch(str));
            str = "9.";
            Console.WriteLine(regex.IsMatch(str));
            str = ".";
            Console.WriteLine(regex.IsMatch(str));

全部为true,应该符合你的要求

chenping2008 | 园豆:9836 (大侠五级) | 2012-12-18 09:41

@chenping2008: 

謝謝你,首先

不過,好像不行,我測試了一下

  Regex regex = new Regex("[1-9]{0,3}.[0-9]{0,4}");
                    if (!regex.IsMatch(ec.CA030.ToString()))
                    {
                        context.Response.Write("格式錯誤");
                        return;
                    }

整數輸入4位也可以通過的。

是這樣的,只要輸入整數   或者 整數和小數

整數位不超過3碼,如果輸入的是整數和小數,整數位不超過3碼,小數位不超過5碼

謝謝

Peter.zhong | 园豆:117 (初学一级) | 2012-12-18 09:55

@Peter.zhong: 小數可以不用輸入的。您上面的是小數點必輸

Peter.zhong | 园豆:117 (初学一级) | 2012-12-18 10:03

@Peter.zhong: 

string str = "999";
            if (str.Contains('.'))
            {
                Regex regex = new Regex("^[1-9]{0,3}.[0-9]{0,5}$");
            }
            else
            {
                var s = "1999";
                Regex regex = new Regex("^[1-9]{0,3}$");
                Console.WriteLine(regex.IsMatch(s));
            }
chenping2008 | 园豆:9836 (大侠五级) | 2012-12-18 11:12
其他回答(2)
0

你确定数据库列的类型可以设置成 numeric(5,8)?大神

收获园豆:1
geass.. | 园豆:1821 (小虾三级) | 2012-12-17 20:29

不好意思,弄錯了,是numeric(8,5)

支持(0) 反对(0) Peter.zhong | 园豆:117 (初学一级) | 2012-12-18 08:32
0

给大神跪了...

收获园豆:1
johnMing | 园豆:223 (菜鸟二级) | 2012-12-18 00:19

不好意思,弄錯了,是numeric(8,5)

支持(0) 反对(0) Peter.zhong | 园豆:117 (初学一级) | 2012-12-18 08:32
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册