我希望我的用户只能以阿富汗国际号码格式输入937XXXXXXXX的电话号码。
到目前为止,我已经编写了以下代码,但它并不像我想要的那样工作:
Private Function Valid_Contact_No(ByVal Contact_No As String, ByRef errorMessage As String) As Boolean
Dim regex As New System.Text.RegularExpressions.Regex("^[937][0-9]{1,11}$")
' Confirm there is text in the control.
If txtContact_no.Text.Length = 0 Then
errorMessage = "Contact No# is required (allowed format: 937XXXXXXXX)"
Return False
End If
If txtContact_no.Text.Length > 11 Then
errorMessage = "Contact_No Can not be more than 11 digits (allowed format: 937XXXXXXXX)"
Return False
End If
If (regex.IsMatch(txtContact_no.Text)) Then
errorMessage = ""
Return True
End If
errorMessage = "A valid Contact No# is required" + ControlChars.Cr
Return False
End Function
任何帮助都将不胜感激 :)