JS
<script>
$('#myInput').on('blur', function() {
var inputValue = $(this).val();
var trimmedValue = inputValue.replace(/^\s+|\s+$/g, '');
$(this).val(trimmedValue);
});
</script>
Explanation:
$('#myInput').on('blur', function() {...});
: This listens for when the input field loses focus (blur event).$(this).val()
: Retrieves the current value of the input field.replace()
: Removes any leading or trailing spaces from the input string.$(this).val(trimmedValue)
: Updates the input field with the trimmed value.
Alternate table row styles
Conditional formatting of table rows
Copy text to clipboard
Disable spaces in an input field
Multi step form with progress indicator
Read more or less
Remove the leading and trailing space
Short functions
Toggle visibility with a slide effect
Toggle visibility without pushing content down
Validate checkboxes
Validate input fields
Validate radio buttons
Validate TinyMce editor