javascript - Regexp with accented characters on match -
this question has answer here:
- how ignore acute accent in javascript regex match? 3 answers
- ignore accent in regex [duplicate] 3 answers
i have check forbidden words in text area when user tries validate. forbidden words list stored in jsblacklist
array, , part of code far :
var fieldvalue = value; var hasforbiddenword = false; (i = 0; < jsblacklist.length; i++) { var regex = new regexp("\\b"+jsblacklist[i]+"\\b","gi"); fieldvalue = fieldvalue.replace(regex, '***'); hasforbiddenword = hasforbiddenword || fieldvalue.match(regex); } value = fieldvalue;
but problem is, jsblacklist
has accented characters, while user write without accent (for example, jsblacklist can have "déjà", , user has typed "deja", "déja" or "dejà").
how can check missing accents ?
nb "marked duplicate" : duplicate questions "regexp without accent check text accents", mine "regexp accent check text potential missing accents".
one way accomplish change black list bit:
replace characters accent same alternation.
for example: "déjà"
to: "d(é|e)j(à|a)"
if blacklist big, want automate replacements, @ end convenient have black list written this.
Comments
Post a Comment