public void insertString(int offs, String str, AttributeSet a)
        throws BadLocationException
    {
        while (this.getLength() > 0 && this.getText(0, 1).equals("0"))
        {
            super.remove(0, 1);
            if (offs > 0)
                offs--;
        }
        super.insertString(offs, p.matcher(str).replaceAll(""), a);
        //remove leading zeros
        if (this.getLength() > 1 && this.getText(0, 1).equals("0"))
            remove(0, 1);
        else if (this.getLength() == 0)
            super.insertString(0, "0", new SimpleAttributeSet());
    }