是否可以使用驗證程序來限制允許輸入的單詞。只能輸入的文字是「house」「flat」「semi」「duplex」文本框稱爲housetype在vb.net是否有可能使用驗證程序來限制在vb.net中允許輸入的文字
0
A
回答
1
您有很多可能性。一種選擇是要創建的單詞列表,允許和使用List.Any extension method這樣的:
dim words as new List(of string) From { "house", "flat", "semi", "duplex" }
dim word = housetype.Text
Console.WriteLine(words.Any (function(w) w = word))
它的優點,它很容易擴展,如果新詞要來(或者如果列表是從讀一個配置文件,等等)。
爲了使代碼更具可讀性,功能可以打包成擴展方法,如if (texBoxControl.ContainsOnlyValidWords()) then ...
。
0
可能是一個更好的解決方案,然後SkorrloreGaming-製作的回答......
Public Function CheckForAllowedWords() As String
Dim ok_word As String
Dim AllowedWords As String() = "house flat semi duplex".Split(" ")
For Each item As String In AllowedWords
If housetype.Text = item Then
ok_word = item
Exit For
Else
Continue For
End If
Next
Return ok_word
End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
CheckForAllowedWords()
If CheckForAllowedWords() <> Nothing Then
MsgBox("Accepted")
Else
MsgBox("Not Accepted")
End If
End Sub
+0
.contains - 那麼你不需要在數組中尋找 – peterG
相關問題
- 1. 是否有可能在VB.NET中複製以下憑據進程?
- 2. 限制在文本框中允許的字符(輸入金額)
- 3. 驗證在vb.net
- 4. VB.NET:如何驗證文本框不允許使用十進制值?
- 5. 是否可以在Java應用程序中限制允許的JRuby命令?
- 6. 無法在VB.NET中禁用必需的字段驗證程序
- 7. 是否有可能在vb.net代碼中使用C++類?
- 8. 如何限制特殊字符,同時允許使用vb.net datagridview中的雙打
- 9. 如何在整個.Net winforms應用程序中限制對有限字符集的輸入。 (vb.net/c#)
- 10. 如何限制用戶只能在vb.net的文本框中輸入整數
- 11. 是否允許在URL中輸入中文字符?
- 12. 是否有在vb.net
- 13. 用戶輸入驗證只有數字和字母允許
- 14. iPhone Enterprise程序是否允許無限制使用UDID?
- 15. InputBox在vb.net中的數字驗證
- 16. EMAILID驗證在vb.net
- 17. 是否有可能在Rails驗證輸入通過JavaScript
- 18. 是否有任何其他方式來驗證VB.net中的文本框的值
- 19. 是否有可能在vb.NET中聲明一個通用事件?
- 20. 是否有可能在vb.net中的組合框中輸入值,如果下拉沒有可用值
- 21. 是否可以在vb.net中更改輸入框圖標?
- 22. 是否有可能減慢VB.NET?
- 23. 允許在輸入驗證時使用特殊命令
- 24. 驗證枚舉值在VB.NET中有效
- 25. 如何在vb.net中允許空列?
- 26. VB.NET中的用戶驗證
- 27. 不允許vb.net程序進入「無響應模式」的技巧
- 28. 是否有可能在VB.NET中獲得OleDbException的特定類型?
- 29. VB.Net - 使用DTD驗證XML
- 30. VB.Net驗證:檢查文本是否僅包含字母
那麼爲什麼你需要的文本框?然後去下拉。 –