devxlogo

Tip Bank

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

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

ReverseString – Reversing a String

‘ Reverse the input string, without using the StrRever function in the VB6 ‘ compatibility assemblyFunction ReverseString(ByVal source As String) As String Dim chars() As Char = source.ToCharArray() Array.Reverse(chars) Return