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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate UK Account Numbers and Sort Codes

Status
Not open for further replies.

BrendanChandler

Programmer
Sep 12, 2000
28
GB
Has anyone written any code to validate UK bank account number and sort codes? I have written simple routines using the Luhn 10 algorithm to validate credit card number entry, however, is there a similar algorithm for UK bank account and sort codes? The same codes I have used do not seem to pass through a Luhn 10 check or through a modulus 11 check. Does anyone know what all the organisations that are selling software that will check your account numbers and sort codes for you are using? Many thanks
 
Hi Brandan,

This is certainly possible, but is more complicated than credit card numbers. Basically, the check digit algorithm for the acccount number varies according to the sort code. I think there are three or four different check digit systems in use.

For a document describing these algorithms, try:

For validating the sort code, the easiest solution might be to check it against the Industry Sort Code Directory. I'm not sure how you might access this, but maybe you could check with BACS.

Hope this helps.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Mike,

Thanks for that. Yes it does appear somewhat more complex than I would have hoped and because the sort code file is changing on a week by week basis it means that I need to keep my software which I am distributing in sync with it - and that's just for the UK! I have written to BACs for more info, however, I suspect I may have to let this one go and leave it to the 3rd party BACs software that sits between my software and BACs. They will still catch the bad codes but unfortunately at payment request time not point of entry so requests could be delayed for a month. I will see what they come back with. Thanks again.

 
Brendan,

Just a thought. I wonder if the sort code directory is available as a web service. Might be worth your while googling around.

I hope you get something sorted. Perhaps you could let us know if you do.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Hi Brendan

I believe you should not check the accountnumber and/or the sortcode separately but you should check the Iban
this is the now by all European banks adopted InternationalBankAccountNumber.
Iban is validated by adding all the numbers, after transforming the letters into numbers and divide by 97, no rest, Ibannumber is valid.

An Ibancheck in FroxPro as follows:

Code:
PARAMETERS pIban2Check
** 1st move first 4 digits to the end
cAcntnmbr2Chck = ALLTRIM(SUBSTR(pIban2Check,5,50))+LEFT(pIban2Check,4)
cAcntInNmbrs = ''
** change all letters into numbers
FOR x = 1 TO LEN(ALLTRIM(cAcntnmbr2Chck))
cAcntInNmbrs = cAcntInNmbrs+TRANSF(IIF(ISALPHA((SUBSTR(cAcntnmbr2Chck,x,1))),;
(ASC(LOWER((SUBSTR(cAcntnmbr2Chck,x,1))))-87),(SUBSTR(cAcntnmbr2Chck,x,1))))
ENDFOR
** Ibannumbers can be > 32 digits FoxPro can't handle these numbers
** so chop into acceptable portions
cMod = TRANSFORM(MOD(VAL(SUBSTR(cAcntInNmbrs,1,9)),97))
FOR T = 10 TO 24 STEP 7
cMod = TRANSFORM(MOD(VAL(cMod+SUBSTR(cAcntInNmbrs,T,7)),97))
ENDFOR
nResult = VAL(cMod)
* nResult = 1 = passed Iban test

Regards,

Koen
 
Mike

Don't forget that a lot of banks have centralised locations for account processing. My own - Lloyds TSB - certainly does, and when I entered my details to cross-check it came up with correct details for the processing centre, headed up by the branch name.

I have tried it with a number of different accounts now and it seems to be right each time.

Shamster
 
Thanks for all the feedback guys. Have received all the info from BACs now and it looks like a whole lot of work for an application where bank accounts and sort codes simply sit on the edge of the application rather than being a central focus therefore on this occasion I am going to skip the validating and let other 3rd party apps further down the line trap the errors. I do, however, think it is worth having a hyperlink to the validator listed close to my input fields so people can check on-line if they wish and as customers start using international bank account details rather than UK ones I will start to introduce validation to my app as listed. Thanks again.
 

Shamster,

a lot of banks have centralised locations for account processing. My own - Lloyds TSB - certainly does

In fact, it was an account at Lloyds TSB that gave me the spurious result I mentioned. Interestingly, the address it gave is in the next street to where I live (where there is no bank branch).

Perhaps this explains why it is so difficult to phone the branch.

BrendanChandler,


I am going to skip the validating ...

You'd think that this would be a common requirement, and that they would do something to make it easier for us programmers. Oh well .....

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Hi Brendan,

Interesting. I have constructed a international valididation, see my previous listing <Iban2Check>. Also I am in the middle of making an validation which 1st checks the national accountnmbr and 2ndly checks the InternationalBankAccountNumber. Not only UK but whole Europe. For most countries it is easy, some a little bit elaborated and for UK one needs tables from BAC. However it seems they will not reveal those tables to foreigners. So if you now have them... and I will get them I will make the full validation for you.

Koen
 
Koen,

Thanks for your offer. It was very straightforward to obtain emailed details from BACs by contacting design@bacs.co.uk. If you have already tried this approach and they have refused the details it would be risking my own relationship with them by passing on the details. Having briefly skimmed the details I understand that details are updated very regularly (fortnightly I think). So unless you are officially 'registered' with them any information passed on could become quickly out of date. Why not try contacting them again on the address above and see if you can justify your case a little better. Surely they understand that overseas software authors have to work with their systems just as authors at home have to. Best of luck.
 
Brendan,

Meanwhile BAC's have replied and supplied me with 5 documents. I will study and come back to you when my UK-validation procedure works.

My assumption BAC's will not supply the data to overseas authors is therefore incorrect.

Koen
 
Brendan,

Found this website by typing bank sort codes into Google.


Hope that helps,

Stewart
PS If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top