formatNRICMY static method

String formatNRICMY(
  1. String nric
)

Implementation

static String formatNRICMY(String nric) {
  var value = nric.trim();
  value = value.replaceAll("-", "");

  if(value.length == 12){
    var firstPart = value.substring(0, 6);
    var secondPart = value.substring(6, 8);
    var thirdPart = value.substring(8, 12);

    return firstPart + "-" + secondPart + "-" + thirdPart;
  }
  return nric;
}