Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression to allow french text as well as english text?

I want to use a regular expression which will allow

  1. English text which does not have a special character.
  2. French Text which does not have a special character.

It will always disallow special characters like @, #, % etc... in both the language.

I have tried with the below code:

if (this.value.match(/[^a-zA-Z0-9 ]/g)) {
    this.value = this.value.replace(/[^a-zA-Z0-9 ]/g, '');
}

It works fine with english text, but the problem is when I provide a french text like éléphant, it considers the french characters as special character, and deletes the french characters. so éléphant becomes lphant.

Is there any way to allow the french characters inside the regular expression?

Thanks a lot in advance.

like image 687
Suvankar Bhattacharya Avatar asked Oct 29 '13 07:10

Suvankar Bhattacharya


2 Answers

Quick solution:

/[^a-zA-Z0-9 àâäèéêëîïôœùûüÿçÀÂÄÈÉÊËÎÏÔŒÙÛÜŸÇ]/

Reference: List of french characters

Hope this helps

like image 170
mortb Avatar answered Nov 07 '22 09:11

mortb


Most simplified solution:

/[^a-zA-ZÀ-ÿ]/  

(or)

/[\wÀ-ÿ]/       // Note: This will allow "_" also

Any of the above regular expression will work in your case.

like image 42
Sam G Avatar answered Nov 07 '22 08:11

Sam G