How i can create a Input a field that accepts only numbers and always add unit at the end?
A solution for accepts only numbers using regex is:
HTML:
<input name="distance">
Javascript (with jQuery):
$('input[name="distance"]').on('input', function() {
this.value = this.value.replace(/[^0-9]/g, '').replace(/^([\d]+)$/g, '$1 km');
});
Works fine, but some problem occours when i tried to use backspace to correct the information.