I am working with a script that I found in a book I bought called ASP.NET: Tips, Tutorials, and Code. The script I am working with is on page 90 of that book. The purpose of the script is to make sure a email address has a valid domain. I believe I have no spelling errors and I recieve an error. Here is my code followed by the error.
Sub btnButton_submit( s As Object, e As EventArgs )
Dim strEmail as String, strPattern as String
strEmail = emailaddress.text
strPattern = "^[\w-_\.]+\@([\w]+\.)+\w+$"
If Not Regex.IsMatch(strEmail, strPattern, RegexOptions.IgnoreCase) Then
errortext.text = "Your Email Address is in the wrong format"
Else
Dim strDomain as String
strDomain = strEmail.Substring(strEmail.IndexOf("@" + 1)
Dim strIP as String
Try
strIP = DNS.Resolve(strDomain).AddressList(0)ToString() ' error is on this line
errortext.text = "Email Domain is correct"
Catch
errortext.text = "Email Domain is incorrect"
End Try
End if
End Sub
Compiler Error Message: BC30311: Value of type 'System.Net.IPAddress' cannot be converted to 'String'.
Source Error:
Line 22: Dim strIP as String
Line 23: Try
Line 24: strIP = DNS.Resolve(strDomain).AddressList(0)ToString()
Line 25: errortext.text = "Email Domain is correct"
Line 26: Catch
Sub btnButton_submit( s As Object, e As EventArgs )
Dim strEmail as String, strPattern as String
strEmail = emailaddress.text
strPattern = "^[\w-_\.]+\@([\w]+\.)+\w+$"
If Not Regex.IsMatch(strEmail, strPattern, RegexOptions.IgnoreCase) Then
errortext.text = "Your Email Address is in the wrong format"
Else
Dim strDomain as String
strDomain = strEmail.Substring(strEmail.IndexOf("@" + 1)
Dim strIP as String
Try
strIP = DNS.Resolve(strDomain).AddressList(0)ToString() ' error is on this line
errortext.text = "Email Domain is correct"
Catch
errortext.text = "Email Domain is incorrect"
End Try
End if
End Sub
Compiler Error Message: BC30311: Value of type 'System.Net.IPAddress' cannot be converted to 'String'.
Source Error:
Line 22: Dim strIP as String
Line 23: Try
Line 24: strIP = DNS.Resolve(strDomain).AddressList(0)ToString()
Line 25: errortext.text = "Email Domain is correct"
Line 26: Catch