function limit(obj, limit) {
var val = obj.value;
if (len(val) > limit) {
val=val.substring(0,limit);
while (len(val) > limit){
val = val.substring(0, val.length - 1);
};
obj.value = val;
}
}
$("#nickName").keyup(function(){
limit(this,20);//Innerhalb von 20 Bytes
})