Reputation: 51
<script type="text/javascript">
$("#title").keyup(function () {
var str = $(this).val();
var trimmed=$.trim(str)
var slug=trimmed.replace(/[^a-z0-9-]/gi, '-').
replace(/-+/g, '-').
replace(/^-|-$/g, '');
var check =slug.toLowerCase();
$("#slug").val(slug.toLowerCase());
});
</script>
I am able to convert english alphanumberic . BUt not able to convert hindi fonts like :
अत्याधुनिक प्रविधि भित्र्याइँदै
Upvotes: 3
Views: 678
Reputation: 51
Now its work for me . I can convert Hindi and English text to slug.
<script type="text/javascript">
$("#title").keyup(function () {
var str = $(this).val();
str.replace(/[`~!@#$%^&*()_\-+=\[\]{};:'"\\|\/,.<>?\s]/g, ' ').toLowerCase();
str.replace(/^\s+|\s+$/gm,'');
var slug=str.replace(/\s+/g, '-');
var trimmed=$.trim(str)
var check =slug.toLowerCase();
$("#slug").val(slug.toLowerCase());
});
</script>
Upvotes: 0
Reputation: 2999
Your function works as intended :
-------------
-
.if you try your function on this string : अत्याधुनिक aze aze प्रविधि भित्र्याइँदै
you will get aze-aze
.
Perhaps you should have a look at transliteration libraries such as https://github.com/andyhu/transliteration
This lib provides a function slugify
that you can use on your hindi string to get an alphanumeric string.
slugify('अत्याधुनिक प्रविधि भित्र्याइँदै')
will give "atyaadhunik-prvidhi-bhitryaaindai"
Upvotes: 3