Validating a VAT number
-
ElseIf txtVAT.Text <> " & IE#######% & " Then MsgBox "Please enter a valid VAT Number starting with IE ", vbExclamation, "Invalid Data" Exit Sub the above is the code i use to ensure a VAT number is entered in correctly (ie an example of a correct VAT number is IE5314569A), however, it throws the message box regardless. What would be the correct syntax? Any help would be greatly appreciated!
-
ElseIf txtVAT.Text <> " & IE#######% & " Then MsgBox "Please enter a valid VAT Number starting with IE ", vbExclamation, "Invalid Data" Exit Sub the above is the code i use to ensure a VAT number is entered in correctly (ie an example of a correct VAT number is IE5314569A), however, it throws the message box regardless. What would be the correct syntax? Any help would be greatly appreciated!
Hi.. Why don't use MaskEdit control ? anyway .. to compare strings use
strComp
function. -
ElseIf txtVAT.Text <> " & IE#######% & " Then MsgBox "Please enter a valid VAT Number starting with IE ", vbExclamation, "Invalid Data" Exit Sub the above is the code i use to ensure a VAT number is entered in correctly (ie an example of a correct VAT number is IE5314569A), however, it throws the message box regardless. What would be the correct syntax? Any help would be greatly appreciated!
First, VB doesn't use wild cards comparing strings. It also doesn't do regular expressions natively. You could use a third party regular expression control like the Regular Expression Library (http://download.com.com/3000-2070-5588590.html?tag=lst-4-10) to validate the input. The other option would be to build another string by scanning the input string and replacing each number with a # character and each letter with a % character. Then your code snippet would work.