Created
May 1, 2013 17:25
-
-
Save lionelB/5496739 to your computer and use it in GitHub Desktop.
Strip accent (and lower case)
This file contains hidden or 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
function strip_accent( str ) { | |
var acc = "ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿñ".split('') | |
, min = "aaaaaaceeeeiiiiooooouuuuyaaaaaaceeeeiiiioooooouuuuyyn".split('') | |
, l = acc.length | |
, i = 0; | |
for(; i < l ; i++) { | |
str = str.replace( new RegExp(acc[i], "g"), min[i]); | |
} | |
return str.toLowerCase(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case
I usually create a field dedicated to sorting / filtering which holds data transformed using this function.
It allow me to do any search / order / filter without worried about accented letters.