daily pastebin goal
41%
SHARE
TWEET

Formatkenteken

a guest Mar 21st, 2015 389 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function formatKenteken(kenteken) {    
  2.      kenteken = kenteken.trim().toUpperCase().replace(/-/g, "");
  3.      pair = 0;    
  4.      if (kenteken.length == 6) {    
  5.        for (var i = 0; i < kenteken.length -1; i++) {
  6.          if (isNaN(kenteken[i]) != isNaN(kenteken[i+1])) {
  7.            kenteken = kenteken.substr(0, i+1) + '-' + kenteken.substr(i+1);
  8.            pair = 0;
  9.            i++;          
  10.          } else {        
  11.            pair++;
  12.            if (pair > 2) {          
  13.              kenteken = kenteken.substr(0, i) + '-' + kenteken.substr(i);
  14.              pair = 0;
  15.            }        
  16.          }        
  17.        }      
  18.      }
  19.      return kenteken;  
  20.    }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top