Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <title>Gerador de Slug © 2023 Mizuno</title>
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
- <body>
- <div class="container">
- <br><br><br>
- <form>
- <div class="form-group">
- <label for="text_field">Informe o texto:</label>
- <input type="text" class="form-control" id="text_field" name="text_field">
- </div>
- <button type="button" onclick="generateSlug()" class="btn btn-primary">Gerar Slug</button>
- </form>
- <div id="output"></div>
- <script>
- function removeSpecialCharacters(text) {
- // Removing accents and cedillas
- var normalizedText = text.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
- // Removing single and double quotes
- var withoutSpecialChars = normalizedText.replace(/[\"\']/g, "");
- return withoutSpecialChars;
- }
- function generateSlug() {
- var text = document.getElementById("text_field").value;
- var slug = removeSpecialCharacters(text).toLowerCase().replace(/ /g,"-").replace(/[^\w-]+/g,'');
- document.getElementById("output").innerHTML = slug;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement