Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2010 Visual Studio 2012 Form1.vb用户输入验证_Visual Studio 2010_Sql Server 2008_Validation - Fatal编程技术网

Visual studio 2010 Visual Studio 2012 Form1.vb用户输入验证

Visual studio 2010 Visual Studio 2012 Form1.vb用户输入验证,visual-studio-2010,sql-server-2008,validation,Visual Studio 2010,Sql Server 2008,Validation,我已经将sql数据库连接到我的vb项目,我需要的最后一个功能是验证用户输入。添加新记录时,需要验证其中两个文本框 txtName是由以下格式组成的第一个文本框:BCO103/T1/01BCO’将始终保持不变,但其余部分需要用户输入。字母和数字需要保持在完全相同的位置 txtModuleID是需要验证的第二个文本框。此字段的数据如下所示:BCO120。同样,BCO将始终保持不变,但3位数字将发生变化 我确信您可以为此使用子字符串 例如: If txtModuleID.Text.Substring(

我已经将sql数据库连接到我的vb项目,我需要的最后一个功能是验证用户输入。添加新记录时,需要验证其中两个文本框

txtName是由以下格式组成的第一个文本框:BCO103/T1/01BCO’将始终保持不变,但其余部分需要用户输入。字母和数字需要保持在完全相同的位置


txtModuleID是需要验证的第二个文本框。此字段的数据如下所示:BCO120。同样,BCO将始终保持不变,但3位数字将发生变化

我确信您可以为此使用子字符串

例如:

If txtModuleID.Text.Substring(0,2) = "BCO" And txtModuleID.Text.Substring... etc Then 'add other conditionals

blnValidated = True

Else

blnValidated = False

End If
子字符串(0,2)表示从0到2。。。使用索引0、1和2中的字母获取输入的子字符串。其余的情况如下


对于第一个输入,请进行详细说明。我不太明白您希望如何验证它。

这是Windows窗体项目吗?你尝试过什么?是的,这是一个Windows窗体项目。我已经尝试过try/catch块和很多IF函数。你想要什么样的行为?错误数据旁边是否出现红色感叹号?或者只是一个简单的消息框,上面写着“字段的格式必须是“BCO”加上3位数”?为每个出错字段单独设置一个消息框,还是一个汇总所有问题的消息框?
If txtModuleID.Text.Trim.ToUpper().SubString(0,2).equals("BCO") and len(txtModuleID.Text.Trim) = 6 Then
   If txtModuleID.Text.Trim.SubString(3,5).isNumeric() Then
       //valid input
   Else
       //message prompt that last 3 digits of the input is not numeric
   End If
Else
       //message prompt that input has invalid format and that input must start with BCO
End IF