Sanitize CSS class names applied on Legend rows/entries

Previously, short names and numbers would be applied as CSS classes, but they would be invalid class names and it would thus be impossible to apply styles to them.

Close #1321.
Shouldn't the regex be more like ^[_a-zA-Z] ?  We only care about the start, but the regex seems? to be looking at any occurrence