In the Netherlands, all people of ages 14 and up receive a Burgerservicenummer (BSN) (Citizen’s Service Number). It is printed on driving licenses, passports and international ID cards, under the header Personal Number. The number is unique and may not contain any information about the person to whom it is assigned. (no information such as gender or date of birth, etc). (source: Wikipedia)

The BSN consists of 9 digits and uses an algorithm often called “the 11-check”. This 11-check algorithm works like this:

```Let's say we perform the 11-check on BSN 123456782
1st digit = 1, 9 * 1 = 9
2nd digit = 2, 8 * 2 = 16
3rd digit = 3, 7 * 3 = 21
4th digit = 4, 6 * 4 = 24
5th digit = 5, 5 * 5 = 25
6th digit = 6, 4 * 6 = 24
7th digit = 7, 3 * 7 = 21
8th digit = 8, 2 * 8 = 16
9th digit = 2, -1 * 2 = -2 (last digit is not added but subtracted)

total: 154

Because 154 can be divided by 11 we can assume 123456782 is valid (154/11=14, no rest 0)

```

So let’s start with creating a custom Validator in our ADF project. This is excellent documented by Mohammed Jabr on his blog.

Create a Java class that implements the javax.faces.validator.Validator Use the following code:

```
package nl.rubix;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

public class BsnValidator implements Validator
{
public BsnValidator()
{
super();
}

public void validate(FacesContext facesContext, UIComponent uIComponent,
Object object) throws ValidatorException
{
String BSN = object.toString();
if (BSN.length()==9)
{
int checksum = 0;
for(int i=0;i<8;i++)
{
checksum = checksum + (Character.digit(BSN.charAt(i),10) * (9-i));
}
checksum = checksum - Character.digit(BSN.charAt(8),10);
// System.out.println("checksum total = " + checksum);
// check Modulus for checksum
if ( (checksum % 11 ) != 0)
{
System.out.println("checksum / 11 is niet 0");
FacesMessage fm = new FacesMessage("BSN fails 11-check");
throw new ValidatorException(fm);
}
else
{
// System.out.println("checksum works !!!");
}
}
else
{
FacesMessage fm = new FacesMessage("BSN must be 9 digits");
throw new ValidatorException(fm);
}
}
}

```

register the custom validator in your WEB-INF/faces-config.xml file Configure the inputText to use the custom validator. Go to the properties of your inputText and make sure you use the correct validatorID:

```
<af:inputText label="BSN:" id="it1">
<f:validator validatorId="bsnvalidator"/>
</af:inputText>

```

References: