陷阱输入 [英] Trap Input

查看:139
本文介绍了陷阱输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起家伙,基本问题.....

1)你如何防止文本框中的负数字输入(-2345等)

2)如何检测/防止在文本框中输入少于8个字符(

,其中密码必须至少包含8个字符)

谢谢。

Sorry guys, basic questions.....
1)how do you prevent negative numeric input in a text box (-2345 etc)
2)how do detect /prevent input of LESS than 8 characters in a text box(
where a password must be a minimum of 8 characters for example)
Thank you.

推荐答案

>对不起家伙,基本问题.....
> Sorry guys, basic questions.....
1)如何防止文本框中的负数字输入(-2345等)
2)如何检测/阻止LESS的输入文本框中的8个字符以上(例如,密码必须至少包含8个字符)
谢谢。
1)how do you prevent negative numeric input in a text box (-2345 etc)
2)how do detect /prevent input of LESS than 8 characters in a text box(
where a password must be a minimum of 8 characters for example)
Thank you.




当用户单击确定,下一步,继续(或者您需要具有的任何标题)按钮,检查TextBox的内容以查看它是否具有形状

你要。如果没有,则弹出一个警告对话框,在用户点击OK

后,将它们带回违规状态。 TextBox所以他们可以更正他们的

条目。


Rick - MVP



When the user clicks on your OK, Next, Continue (or whatever caption you
have) button, check the contents of the TextBox to see if it has the "shape"
you want. If not, pop up a warning dialog box and, after the user clicks OK
on it, take them back to the "offending" TextBox so they can correct their
entry.

Rick - MVP




" nkp" <我们*********** @ btinternet.com>在消息中写道

新闻:bm ********** @ sparta.btinternet.com ...

"nkp" <we***********@btinternet.com> wrote in message
news:bm**********@sparta.btinternet.com...
对不起家伙,基本问题.... 。
1)如何防止文本框中的负数字输入(-2345等)
2)如何在文本框中检测/阻止少于8个字符的输入(
密码必须至少8个字符,例如)
谢谢。
Sorry guys, basic questions.....
1)how do you prevent negative numeric input in a text box (-2345 etc)
2)how do detect /prevent input of LESS than 8 characters in a text box(
where a password must be a minimum of 8 characters for example)
Thank you.




1.

你的SUB

如果VAL(TRIM(Text1.Text))> = 0那么

''处理有效的数字输入

ELSE
''让用户知道,例如

MSGBOX(仅限非负数)

结束如果


如果LEN(TRIM(Text1.Text))> 7那么

''有效用户密码

ELSE

''让用户知道。这里可能需要一个柜台

''如果它超过3就退出程序或

''这样的东西

MSGBOX("密码错误。再试一次。

结束如果




1.
YOUR SUB

IF VAL(TRIM(Text1.Text)) >= 0 THEN
''handle valid numerical entry
ELSE
''let user know, e.g
MSGBOX("non-negative numbers only please")
END IF

IF LEN(TRIM(Text1.Text)) > 7 THEN
'' valid user password
ELSE
'' let user know. Might need a counter here
'' like if it exceed 3 to quit the program or
'' something like that
MSGBOX("Incorrect password. try again.")
END IF



''仅限正数:

私有子Text1_Change()

如果不是IsNumeric(Text1.Text)那么

Text1.Text =""

结束如果

结束子


通常,为确保用户只输入文本字段中的数字,您需要

在输入文本时验证文本。文本框的Change()事件提供了

这样做的最佳位置。但是,仅使用IsNumeric()函数单独使用
就不会有诀窍。例如,假设用户输入了否定的

数字。 IsNumeric()函数根本不会看到它并将返回

错误。有一种解决方法。

私有子Text1_Change()

如果不ValidateNumeric(Text1.Text)那么

Text1.Text =" ;"

结束如果

结束子


私有函数ValidateNumeric(strText As String)_

As Boolean

ValidateNumeric = CBool​​(strText ="" _

or strText =" - " _

or strText =" - 。" _

或strText ="。" _

或IsNumeric(strText))

结束函数

" nkp" <我们*********** @ btinternet.com>在消息中写道

新闻:bm ********** @ sparta.btinternet.com ...
''Positive numbers only:
Private Sub Text1_Change()
If Not IsNumeric(Text1.Text) Then
Text1.Text = ""
End If
End Sub

Often, to ensure that users enter only numbers in a text field, you''ll want
to validate the text as they enter it. The textbox''s Change() event provides
the best place to do so. However, simply using the IsNumeric() function
alone won''t do the trick. For instance, suppose the user entered a negative
number. The IsNumeric() function simply wont see it and will return an
error. There is a way around this.
Private Sub Text1_Change()
If Not ValidateNumeric(Text1.Text) Then
Text1.Text = ""
End If
End Sub

Private Function ValidateNumeric(strText As String) _
As Boolean
ValidateNumeric = CBool(strText = "" _
Or strText = "-" _
Or strText = "-." _
Or strText = "." _
Or IsNumeric(strText))
End Function
"nkp" <we***********@btinternet.com> wrote in message
news:bm**********@sparta.btinternet.com...
对不起家伙,基本问题.... 。
1)如何防止文本框中的负数字输入(-2345等)
2)如何在文本框中检测/阻止少于8个字符的输入(
密码必须至少为8个字符,例如)
谢谢。
Sorry guys, basic questions.....
1)how do you prevent negative numeric input in a text box (-2345 etc)
2)how do detect /prevent input of LESS than 8 characters in a text box(
where a password must be a minimum of 8 characters for example)
Thank you.



这篇关于陷阱输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆