Is possible to add a String.contains more than one value?
我想创建一个控件,当我创建一个CompanyId时,不允许创建带有特殊字符的ID,例如(
您可以使用
1 2 3 4 | Dim disallowed ="&/" If disallowed.Intersect(txtIdCompany.Text).Any() Then ' alert error message End If |
这是使用
的类似方法
1 2 3 | If txtIdCompany.Text.Any(AddressOf disallowed.Contains) Then ' alert error message End If |
使用
的第三个选项
1 2 3 | If txtIdCompany.Text.IndexOfAny(disallowed.ToCharArray()) >= 0 Then ' alert error message End If |
1 2 3 4 5 | If txtIdCompany.Text.Contains("&") Or txtIdCompany.Text.Contains("") Or txtIdCompany.Text.Contains("/") Then // alert error message End If |