Skip to content

Instantly share code, notes, and snippets.

@williaanlopes
Last active October 30, 2020 00:42
Show Gist options
  • Save williaanlopes/331c04a6cdb8ce77836500faf2c723ae to your computer and use it in GitHub Desktop.
Save williaanlopes/331c04a6cdb8ce77836500faf2c723ae to your computer and use it in GitHub Desktop.
jQuery helper functions like PHP (ucwords, strtoupper, strtolower) functions
$('.capitalize').on('keyup', function(e) {
if (e.target.value && e.target.value != "") {
$(this).val(e.target.value.toUpperCase());
}
});
$('.capitalize-first').on('keyup', function(e) {
if (e.target.value && e.target.value != "") {
$(this).val(e.target.value.replace(/(^\w{1})|(\s{1}\w{1})/g, match => match.toUpperCase()));
}
});
$('.uncapitalize').on('keyup', function(e) {
if (e.target.value && e.target.value != "") {
$(this).val(e.target.value.toLowerCase());
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment