devxlogo

March 31, 2003

IsValidPath – Validating a system path

‘ Validate a system path’ Example:’ MessageBox.Show(IsValidPath(“C:TestMemo.txt”)) ‘ => True’ MessageBox.Show(IsValidPath(“\RemotePCTestMemo.txt”)) ‘ => True’ MessageBox.Show(IsValidPath(“C:TestMem|o.txt”)) ‘ => FalseFunction IsValidPath(ByVal path As String) As Boolean Try Dim f As New System.IO.FileInfo(path)

IsValidUsPhoneNumber – Validating a US phone number

‘ Validate a US phone number’ Example:’ MessageBox.Show(IsValidUsPhoneNumber(“(123) 456-7890”)) ‘ True’ MessageBox.Show(IsValidUsPhoneNumber(“(123) 456-78901”)) ‘ FalseFunction IsValidUsPhoneNumber(ByVal phnNum As String) As Boolean Return System.Text.RegularExpressions.Regex.IsMatch(phnNum, _ “^(((d{3}) ?)|(d{3}-))?d{3}-d{4}$”)End Function

IsValidUsSSN – Validating a US Social Security Number (SSN)

‘ Validate a US Social Security Number’ Example:’ MessageBox.Show(IsValidUsSSN(“123-12-1234”)) ‘ True’ MessageBox.Show(IsValidUsSSN(“123-123-1234”)) ‘ FalseFunction IsValidUsSSN(ByVal ssn As String) As Boolean Return System.Text.RegularExpressions.Regex.IsMatch(ssn, _ “^d{3}-d{2}-d{4}$”)End Function

IsValidIP – Validating an IP address

‘ Validate an IP address’ Example:’ MessageBox.Show(IsValidIP(“123.14.0.255”)) ‘ => True’ MessageBox.Show(IsValidIP(“256.14.0.255”)) ‘ => FalseFunction IsValidIP(ByVal ipAddress As String) As Boolean Return System.Text.RegularExpressions.Regex.IsMatch(ipAddress, _ “^(25[0-5]|2[0-4]d|[0-1]?d?d)(.(25[0-5]|2[0-4]d|[0-1]?d?d)){3}$”)End Function

IsValidUrl – Validating a URL

‘ Validate a URL’ Example: MessageBox.Show(IsValidUrl(“http://www.vb2themax.com”))Function IsValidUrl(ByVal url As String) As Boolean Return System.Text.RegularExpressions.Regex.IsMatch(url, _ “(http|ftp|https)://([w-]+.)+(/[w- ./?%&=]*)?”)End Function

IsValidUsZip – Validating a US ZIP code

‘ Validate a US ZIP code’ Example:’ MessageBox.Show(IsValidUsZip(“12345”)) ‘ => True’ MessageBox.Show(IsValidUsZip(“12345-1234”)) ‘ => True’ MessageBox.Show(IsValidUsZip(“12345-12345”)) ‘ => FalseFunction IsValidUsZip(ByVal zip As String) As Boolean Return System.Text.RegularExpressions.Regex.IsMatch(zip, _ “^(d{5}-d{4})|(d{5})$”)End Function

IsValidEmail – Validating an e-mail address

‘ Validate an e-mail address’ Example:’ MessageBox.Show(IsValidEmail(“[email protected]”)) ‘ True’ MessageBox.Show(IsValidEmail(“vb2themax.com”)) ‘ False’ MessageBox.Show(IsValidEmail(“mbellinaso@vb2themax”)) ‘ FalseFunction IsValidEmail(ByVal email As String) As Boolean Return System.Text.RegularExpressions.Regex.IsMatch(email, _ “^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$”)End Function