关于电话号码的自定义验证器及其进一步信息



我正在寻找一个能详细解释CustomValidator的好网站。如果有人想去,请告诉我。以下代码检查结果中是否至少有10个数字。然而,我希望它也能验证这些值是数字。在vb.net中使用CustomValidator,有没有一种方法可以作为"and if"语句来实现这一点?

谢谢

Sub AtLeastTenNumbers_ServerValidate(ByVal source As Object, _
ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
    If area_code.Text.Length + phone_1.Text.Length + phone_2.Text.Length > 9 Then
        args.IsValid = True
    Else
        args.IsValid = False
    End If
End Sub

这是一篇有点老的文章,但Scott Mitchell知道他的东西:

https://web.archive.org/web/20211020145934/https://www.4guysfromrolla.com/articles/073102-1.aspx

有没有一种方法可以作为"and if"语句来实现这一点?

您可以始终在当前语句中嵌套if语句。

If area_code.Text.Length + phone_1.Text.Length + phone_2.Text.Length > 9 Then 
    args.IsValid = True 
    'Check to see if this part is numeric
    If IsNumeric(phone_1.Text) Then
       ' Do Logic here
    End If
Else 
    args.IsValid = False 
End If 

最新更新