int.TryParse [英] int.TryParse
问题描述
我在网页上有一个文本框,我希望用户能够输入
信用卡/借记卡发行号码(如果有的话)。这些数字有时会使用
一个前导零。如果我使用int.TryParse函数来确保没有
字母字符,如果数字是例如01或
02,它会返回false吗?
TIA
-
ats @ jbex
当一位老太太被一辆卡车撞到
我看到你眼中的邪恶光芒
亚当和蚂蚁 - 鞭打我的诅咒
" ats @ jbex" < al *** @ allenjones.NOSPAM.co.PLEASE.ukwrote in message
news:9q ********************* *******@40tude.net
我在网页上有一个文本框,我希望用户能够输入一个
信用卡/借记卡发卡号码(如果有)。这些数字
有时使用前导零。如果我使用int.TryParse函数
确保没有字母字符,如果
数字是例如01或02,它会返回false吗?
有几种选择。您可以使用Cint或IsNumeric,但它们都允许使用十六进制表示法。如果您使用的是VB 2008,我会使用它:
如果Textbox1.Text.All(函数(c)Char.IsDigit(c))那么
01和02是整数,所以我不明白为什么TryParse不会返回true。
这也很容易通过自己而不是问......
-
Patrice
" ats @ jbex" < al *** @allenjones.NOSPAM.co.PLEASE.ukaécritdansle message de
groupe de discussion:9q **************** ************ @ 40tude.net ...
我在网页上有一个文本框,我希望用户能够输入
信用卡/借记卡发卡号(如果有)。这些数字有时会使用
一个前导零。如果我使用int.TryParse函数来确保没有
字母字符,如果数字是例如01或
02,它会返回false吗?
TIA
-
ats @ jbex
当一位老太太被一辆卡车撞到
我看到你眼中的邪恶光芒
亚当和蚂蚁 - 鞭打我的价值
9月19日,11:15 * am,ats @jbex < al ... @ allenjones.NOSPAM.co.PLEASE.uk>
写道:
我在网络上有一个文本框我希望用户能够输入
信用卡/借记卡发行号的页面(如果有的话)。这些数字有时会使用
一个前导零。如果我使用int.TryParse函数来确保没有
字母字符,如果数字是例如01或
02,它会返回false吗?
TIA
-
ats @ jbex
当一位老太太被一辆卡车撞到
我看到你眼中的邪恶光芒
亚当和蚂蚁 - 鞭打我的价值
我强烈建议您在页面中添加一个ASP.NET验证
控件来进行初始客户端检查。一个
策略是使用正则表达式验证器来解析输入格式,
确保没有字母字符或信用卡
number是有效的格式(xxxx-xxxx-xxxx-xxxx)。
一如既往,我强烈推荐一款名为Expresso的产品来创建
正则表达式,它可以免费使用,可以为您节省大量时间:
http://www.ultrapico.com/Expresso.htm
谢谢,
Seth Rowe [ MVP]
http://sethrowe.blogspot.com/
I have a textbox on a web page that I want users to be able to enter a
credit/debit card issue number if there is one. These numbers sometimes use
a leading zero. If I use the int.TryParse function to ensure there are no
alpha characters will it return false if the number is for instance 01 or
02?
TIA
--
ats@jbex
When an old lady got hit by a truck
I saw the wicked gleam in your eyes
Adam and The Ants - Whip In My Valise
Hi,
"ats@jbex" <al***@allenjones.NOSPAM.co.PLEASE.ukwrote in message
news:9q****************************@40tude.netI have a textbox on a web page that I want users to be able to enter a
credit/debit card issue number if there is one. These numbers
sometimes use a leading zero. If I use the int.TryParse function to
ensure there are no alpha characters will it return false if the
number is for instance 01 or 02?
There''s a couple of options. You can use Cint or IsNumeric but they both
allow hex notation. IF you are using VB 2008 I would use this:
If Textbox1.Text.All(Function(c) Char.IsDigit(c)) Then
01 and 02 are integers so I don''t see why TryParse wouldn''t return true.
Also it would be really easy to try this by yourself rather than asking...
--
Patrice
"ats@jbex" <al***@allenjones.NOSPAM.co.PLEASE.uka écrit dans le message de
groupe de discussion : 9q****************************@40tude.net...I have a textbox on a web page that I want users to be able to enter a
credit/debit card issue number if there is one. These numbers sometimes
use
a leading zero. If I use the int.TryParse function to ensure there are no
alpha characters will it return false if the number is for instance 01 or
02?
TIA
--
ats@jbex
When an old lady got hit by a truck
I saw the wicked gleam in your eyes
Adam and The Ants - Whip In My Valise
On Sep 19, 11:15*am, "ats@jbex" <al...@allenjones.NOSPAM.co.PLEASE.uk>
wrote:I have a textbox on a web page that I want users to be able to enter a
credit/debit card issue number if there is one. These numbers sometimes use
a leading zero. If I use the int.TryParse function to ensure there are no
alpha characters will it return false if the number is for instance 01 or
02?
TIA
--
ats@jbex
When an old lady got hit by a truck
I saw the wicked gleam in your eyes
Adam and The Ants - Whip In My ValiseI would highly recommend you add one of the ASP.NET validation
controls to the page to do some initial client-side checking. One
strategy would be to use a Regex Validator to parse the input format,
ensuring there are no alphabetic character or that the credit card
number is in a valid format (xxxx-xxxx-xxxx-xxxx).
As always, I highly recommend a product called Expresso for creating
Regex expressions, it''s free to use and can save you tons of time:
http://www.ultrapico.com/Expresso.htm
Thanks,
Seth Rowe [MVP]
http://sethrowe.blogspot.com/
这篇关于int.TryParse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!