How to allow a regular expression of letters and numbers to accept cedilla

Asked

Viewed 985 times

1

I need the regular expression to accept the key c cedilla.

$('[name="txtEndereco"]').keyup(function () { 
    this.value = this.value.replace(/[^a-zA-Z 0-9]+/g,''); 
});
  • 1

    /[^a-zA-ZçÇ 0-9]+/g?

  • It would be something like that? 'çedilh!a'.replace(/[^A-zÀ-ÿ\s\d]/, ''); // dá çedilha

  • 1

    This way it worked''replace(/[ a-za-Zçç 0-9]+/g,')'' @Sergio.

  • 1

    Mark his answer as the correct answer

2 answers

4


/[^a-zA-ZçÇ 0-9]+/g

Working with regex in accented letters is +/- difficult in Javascript.

In other languages there is the class \p{L} which includes all characters that are letters. In Javascript sometimes it is best to add the cases that are accurate.

1

Using [À-ã] picks up cedilla, uncle, severe accent, acute accent, circumflex accent etc. I had problems and used this expression, it worked very well.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.