org.notima.generic.businessobjects.util.TaxIdFormatter Maven / Gradle / Ivy
package org.notima.generic.businessobjects.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Utility class to parse and print tax id:s in different formats.
*
* At the moment only Swedish tax id's are supported.
*
* @author Daniel Tamm
*
*/
public class TaxIdFormatter {
private static Pattern se10 = Pattern.compile("^(\\d{2})(\\d{2})(\\d{2})(\\d{4})$");
private static Pattern se11 = Pattern.compile("^(\\d{2})(\\d{2})(\\d{2})\\-(\\d{4})$");
private static Pattern se12 = Pattern.compile("^(\\d{4})(\\d{2})(\\d{2})(\\d{4})$");
private static Pattern se14 = Pattern.compile("^SE(\\d{2})(\\d{2})(\\d{2})(\\d{4})01$");
/**
* Remove all non digit characters
*
* @param cleanUp String to be cleaned.
* @return A cleaned string.
*/
public static String toDigitsOnly(String cleanUp) {
if (cleanUp==null) return("");
StringBuffer buf = new StringBuffer();
char c;
for (int i=0; i='0' && c<='9') {
buf.append(c);
}
}
return(buf.toString());
}
public static boolean hasDigitsOnly(String ref) {
if (ref==null || ref.trim().length()==0) return(false);
char c;
for (int i=0; i='0' && c<='9')) {
return(false);
}
}
return true;
}
/**
* Remove blanks from a string.
*
* @param cleanUp String to clean up.
* @return A string without blanks.
*/
public static String removeBlanks(String cleanUp) {
if (cleanUp==null) return null;
StringBuffer result = new StringBuffer();
char c;
for (int i=0;i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy