Created
July 26, 2023 05:50
-
-
Save Mahendran-Balaji/35fbb00c0511b9aaf49df6d6d83da11c to your computer and use it in GitHub Desktop.
Create Slug URL using Javascript
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
/* Javascript string replace spaces with dash using replace() */ | |
/* | |
* Allowed only lower case letters (a-z) | |
* Here, the Regular expression is /\s+/g. | |
*/ | |
$('#slug-url').bind('keyup blur', function() { | |
var $th = $(this); | |
$th.val($th.val().replace(/(\s{2,})|[^a-z ']/g, ' ')); | |
$th.val($th.val().replace(/\s+/g, '-')); | |
$th.val($th.val().replace(/^\s*/, '')); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment