Last active
October 30, 2020 00:42
-
-
Save williaanlopes/331c04a6cdb8ce77836500faf2c723ae to your computer and use it in GitHub Desktop.
jQuery helper functions like PHP (ucwords, strtoupper, strtolower) functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.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