Jump to content

Accent Convertor


djp1988
 Share

Recommended Posts

Hello everyone !I haven't posted for a little while now, I'm currently working on some small projects, and I'm right stuck into some string manipulation, my current project includes typing into an input (type="text"), and a list appears with names, with which the current input value matches some part of the names,But I ran into a problem where "Me" wouldn't trigger a suggestion for "lanie", so I started to write an accent remover function, so I could store the search criteria and names with accents removed so "Me" would find "Mé" and also "Mé" finds "Me" as behind the scenes, I'm also removing accents from the criteria, so I decided to paste my function here so anyone who finds it helpful may use it, Please also send your feedback if I've forgotten any accents.

function remove_accents(s){	var accents = {		'é':'e', 		'è':'e', 		'ê':'e', 		'ë':'e',		//upper		'É':'e',		'È':'e',		'Ê':'e',		'Ë':'e',				'æ':'ae',		//upper		'Æ':'ae',				'à':'a', 		'à':'a', 		'â':'a', 		'ä':'a', 		'å':'a', 		'à':'a',		//upper		'À':'a',		'É':'a',		'Â':'a',		'Ä':'a',		'Å':'a',				'ç':'c',		//upper		'Ç':'c',				'ì':'i',		'í':'i',		'î':'i',		'ï':'i',		//upper		'Í':'i',		'Î':'i',		'Ï':'i',		'Ì':'i',				'ñ':'n',		//upper		'Ñ':'n',				'ò':'o',		'ó':'o',		'ô':'o',		'ö':'o',		'õ':'o',		'ø':'o',		//upper		'Ó':'o',		'Ò':'o',		'Ô':'o',		'Ö':'o',		'Õ':'o',		'Ø':'o',				'œ':'oe',		//upper		'Œ':'oe',				'ù':'u',		'ú':'u',		'û':'u',		'ü':'u',		//upper		'Ù':'u',		'Ú':'u',		'Û':'u',		'Ü':'u',				'ÿ':'y',		//upper		'Ÿ':'y'		};	for(i in accents){		var re = new RegExp(i,"g");		s = s.replace(re,accents[i]);	}	return s;}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...