
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎07-22-2021 08:11 AM
This is a very straight-forward script to take a person's name, strip out accents and special characters and spaces for the purpose of using in a user id or an email address.
// Caveat : I am 💯% mixing names and genders around in my example
// just to get names with accents, etc.
//
// This is just for demonstration and is not an attempt at representing
// real name combinations
var firstname = "Frédéric-Noël" ;
var lastname = "Jokūbas_KŠthe Smith"
var result = {
first: normalise( firstname ),
last : normalise( lastname )
} ;
console.info(result) ;
function normalise (input) {
return input
.toString() // Just in case, you know what I mean
.normalize('NFD') // Canonical Decomposition
.replace(/[\u0300-\u036f]/g, "") // Remove diacritics
.replace(/\s/g,"") // Strip spaces
.replace(/[\W_]+/g,"") // Strip all non-word characters and underlines
;
}
// [object Object] {
// first: "FredericNoel",
// last: "JokubasKStheSmith"
// }
- 4,008 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks very much, this was exactly what I needed.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi
I have solved above problem like below code
ä ---> ae
ë ---> e
ï ---> i
ö ---> oe
ü ---> ue
ÿ ---> y
ß --> ss
please help me how to translation of the umlauts like above.
Thanks & Regards,
Bandi
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
This script only works on background & not on the script includes.
Did you find a way around this?

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Do you mean mine, or "Community Alums"'s? Because mine definitely works in a script include. There is legit nothing special about. It is as vanilla JS as it comes.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
"Community Alum"'s question has to do with transliteration. And I have done some research and have found the answer.
You can include speakingurl as a script include from its CDN, either the full one or the minified one. Perform the transliteration before you perform the normalisation.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
My Bad, it seems to be working. Need to pass the inputs as String.