Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

complicated Address handling for AVS

Status
Not open for further replies.

tlhawkins

Programmer
Dec 28, 2000
797
US
Hey,

I need a function that can take an address and boil it down into just the numbers, but I need to know all the different options of numbers. For instance with this address:

1125 Hwy101 Apt 7

I would need to return:

1125, 101, 7, 1125101, 11257, 1017, and 11251017 (there may be more options I can't see?)

Can anyone think of a way to do this? I can get close with a loop inside a loop but it misses a lot of the combinations.

Thanks

Travis Hawkins
 
While I think I have a couple methods you could try, this sounds an awful lot like a homework assignment. If you give us some more information on what your trying to do (ie, like not a homework assignment) we would be able to help.

Best MS KB Ever:
 
Thanks Tarwn,

I actually did find a solution with 3 loops inside each other, a lot of double checking and an extra function to check if we already had that combination.

And "No", it's not a homework assignment. Apparently those homework assignments do sometimes have real world applications as this is an improvement to an existing CC processing function.

You see, the number that AVS systems use to compare against an address is entered by a bank employee someplace and they are apparently not given much direction on how to do it. They only enter the Number portion of the address so an address like: "701 Maple st". would be entered as 701.

The problem is when you have an address like "217 23rd St. Apt. 5"

That MAY be entered as 217, or 23, or, 5, or 21723, or 2175, or 217235, or 235. All depending on the person who types it in. This results in many AVS checks failing even though the address is actually correct.

The function I built will allow multiple address checks before flagging a sale as fraud. This is very important for businesses that can't afford fraudulent charges and therefore abort the sales process if the address can not be verified.

Thanks for your interest in the project though, and if you do have some methods I haven't thought of I'm always open to improvements.

Travis Hawkins
 
Thank you for your explanation. I realize there are sometimes things we are forced to do in the real world that appear as if they are homework assignments, thats why I prefer to ask.

The easiest way I could think of to extract the numbers would be a regular expression. I have another thought if your trying to compare two records but I'll get into that afterwards.
Basically with a regular expression you could specify something simple like "\d+" as the pattern, execute it against your string, and receive back a collection of all numbers in the string. Something like:
Code:
Dim objRegExp
Set objRegExp = New RegExp
objRegExp.Global = True
objRegExp.Pattern = "\d+"

Dim matches, match
Set matches = objRegExp.Execute(yourString)
For Each match in matches
   Response.Write "Found: " & match.Value
Next

Set objRegExp = Nothing

Honestly I can't think of a better way to combine these than a series of loops. Maybe the coffee hasn't completely kicked in yet.


Now the other method I considered is only available if you are checking one input against one address field (ie, you have pulled a single field for the credit card number already). Basically you could do a character by character comparison through the first [string to verify] string looking for characters from the second [entered numeric string]. By looping through the second string looking for matching characters from the first you can ensure that all the numbers from the second string exist in the same order in the first string, even if there happen to be more letters and other numbers. Something like:
Code:
Dim stToVerify : stToVerify = "217 23rd St. Apt. 5"
Dim stOfficial : stOfficial = "217235"
Dim pos, vpos
vpos = 1
For pos = 1 To Len(stOfficial)
   'advance through the entered string
   Do While vpos < Len(stToVerify) + 1
      'found a matching character, increment pos and return
      If Mid(stToVerify,vpos,1) = Mid(stOfficial,pos,1) Then
         vpos = vpos + 1
         Exit Loop
      End If
      'didn't find match, advance to next character
      vpos = vpos + 1
   Loop
   'if we have run out of characters to verify, jump out
   If vpos > Len(stToVerify) + 1 Then Exit For
Loop

'Verification means the pos counter is past the end of the official string
If pos > Len(stOfficial) Then
   Response.Write "Success: All characters from official were matched"
Else
   Response.Write "Failed. At least one character could not be found."

Now that I have done that I thought of a way to combine these efforts. A single loop through the official string would allow us to build a regular expression based on it, at which point we would only have to make sure that the string to verify matches the pattern. Something like:
Code:
Dim stToVerify : stToVerify = "217 23rd St. Apt. 5"
Dim stOfficial : stOfficial = "217235"
Dim objRegExp, pattern, pos

'build a pattern based on the official set of numbers
pattern = ".*"
For pos = 1 to Len(stOfficial)
   pattern = pattern & Mid(stOfficial,pos,1) & ".*"
Loop

'test the string to verify with the pattern
Set objRegExp = New RegExp
objRegExp.Global = True
objRegExp.Pattern = pattern
If objRegExp.Test(stToVerify) Then
   Response.Write "Success: All the numbers in the official string appear in the same order in the verify string"
Else
   Response.Write "Fail: something didn't match"
End If

In any case, I haven't tested any of the code I wrote above, as I wrote it directly into the post, but it should be close enough to give you the idea I was going for in each one. The second two are slightly less secure than the first method in that they can be broken if the end user is allowed to enter inordinately long strings for an address line (ie, 80-???? characters without spaces, letters, or special characters)

-T

Best MS KB Ever:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top