Validation of Norwegian ID number and account number

Good morning!
We are wondering if it is possible to create a validation of Norwegian ID number and account number in Appfarm?

We are creating employees and need to have valid ID numbers and account numbers in order for the employee ID to be created, and therefore wish to have a validation in place to minimize issues.

Look forward to your help!


Appfarm supports regex in the global data model on the string property, where you can paste the regex that you want your field to be validated against. This validation will only be run on persist, so you would have to handle the exception that will be thrown (PropertyValidationError) if the string does not match the defined regex expression. If the validation fails then the object as a whole is rejected by the server.

For both SSNs and account number I assume that you would check that the string matches a certain pattern (regex) as well as verifying that the checksums in the SSN/account number are correct. Matching regex is fairly straight forward in javascript, while you would have to implement some logical checks as well to verify that the checksums are correct. I believe the same applies for IBAN-numbers, while bank account numbers may follow certain formats based on the different banks.


  • You could enforce a regex on your string property in the global data model to ensure that only strings matching that regex will be accepted on the server side. This does not, however, do any checksum calculation and you would have to persist the object before it would be validated.

  • If your App you could have an action with name “Validate SSN” that could be triggered from the UI. This could have an decision node with a function expression that returns either true or false based on the regex and any other checks that you would do.

If we add the ssn property to our function as a function parameter, we could do something like this (I believe the regex is only for SSN and not D-numbers, so it may require some alteration to serve both). We only verify the checksums, so it could/should be extended with any checks for other parts of the number as well (if required).

const cleanedSSN = ssn.replace(/\D/g, ''); // Remove non-digit characters

const norwegianSSNRegex = /(0[1-9]|[1-2][0-9]|31(?!(?:0[2469]|11))|30(?!02))(0[1-9]|1[0-2])\d{7}/;

  if (!norwegianSSNRegex.test(cleanedSSN)) {
    return false; // Invalid format

  const digits = cleanedSSN.substr(0, 11).split('').map(Number); // Extract the digits as an array

  const checksum10 = [3, 7, 6, 1, 8, 9, 4, 5, 2, 1]
  const checksum11 = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]

  let sum10 = 0;
  for (let i = 0; i < 10; i++) {
    sum10 += digits[i] * (checksum10[i]);

  let sum11 = 0;
  for (let i = 0; i < 11; i++) {
    sum11 += digits[i] * (checksum11[i]);

  const calculatedChecksum10 = sum10 % 11
  const calculatedChecksum11 = sum11 % 11

  return calculatedChecksum10 === 0 && calculatedChecksum11 === 0

These resources may be helpful:

Good luck! :smile:


Thank you for your very helpful reply!