regular expression with jquery and accented characters
i'm looking for a regular expression to validate an input : in France, we can use accented characters in name, and i don't find anything i can use. please, can you help me to find how to do a regular expression for: -any letter -any accented letter -spaces - and the sign "-" (without quotes)
i've try something like but it don't seem to be working.. var regealpha =/[^A-Za-z0-9ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ]/;
thx for help 开发者_如何学JAVA(and sorry for my poor english... i'm a froggy ^^ )
JavaScript doesn't seem to have good internationalization options. The symbol \w will give you all [A-Za-z0-9_], but you'll need to stipulate your own chars in addition to this.
You seem to be quite close. The following regex should work for you:
/[\wÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ]/g
See it working at this jsfiddle:
http://jsfiddle.net/jameswiseman/3H2mJ/1/
You'll see that the regex replaces everything in the input string "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ"
with 'z'.
EDIT
I think this is what you need:
/[^a-zA-ZÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ]/
It will tell you if there are characters NOT in the above set. So
var myRegex = /[^a-zA-ZÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ]/;
"C3P0".test(myRegex ); //returns true --> Report Error!
"kangun".test(myRegex ); //returns false --> OK :-)
"kàngun".test(myRegex ); //returns false --> OK :-)
Also have a look at this JSFiddle
I know it is long, but if that is what is needed then then you should use it.
Maybe you want to use \p{L}
(as described here), which matches a unicode letter.
精彩评论