0

I have a textfield for entering a name. No numbers or punctuation is allowed here. Only letters are allowed and dashes, also letters like é, è, à, ç, ...

Which regular expression do I need to use?

wvp
  • 1,134
  • 5
  • 15
  • 28
  • Why and if so, how do I do it. I'm quiet new to Stackoverflow – wvp Jun 06 '12 at 12:10
  • 1
    Read [here](http://stackoverflow.com/faq#howtoask) – Prince John Wesley Jun 06 '12 at 12:15
  • Agree with all - please accept your previous question's answer as well, guys put their effort to help you, its a token gesture of thanks `:)` cheers! and read the link above i.e. http://stackoverflow.com/faq#howtoask – Tats_innit Jun 06 '12 at 12:27

2 Answers2

0

If the list of characters you want to exclude is small, you should probably use something like

[\d\.,;]

+ whatever other punctuation/non-word marks you want to exclude (`,',(,), etc seem like reasonable candidates, some of which will need to be escaped - probably should review a site like this for the whole shebang), and check that against your text. If it pops, fail the validation. The brackets above form what's called a character class or character set. The class will match anything that occurs between them once - more or fewer times if you apply a regex modifier (+, ?, ., etc).

Carl
  • 7,538
  • 1
  • 40
  • 64
0

working demo http://jsfiddle.net/zCZdX/3/ updated http://jsfiddle.net/48JW4/

Good link: http://www.hanselman.com/blog/InternationalizedRegularExpressions.aspx

Assuming you will add spaces and dash as you mentioned this should suffice your need.

Hope this helps and added image for your convenience.

Also please start accepting answer or every one get demoralized to help without any zeal from OP :)

oh and read this: JavaScript validation issue with international characters

code (rest feel free to play around with fiddle)

this.value = this.value.replace(/[^\w\-\s\dÀÈÌÒÙàèìòùÁÉÍÓÚÝáéíóúýÂÊÎÔÛâêîôûÃÑÕãñõÄËÏÖÜäëïöüçÇߨøÅ寿ÞþÐð]+$/g,'');

IMAGE

enter image description here

Community
  • 1
  • 1
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
  • One more thing... I removed the \d because I don't want numbers, but still I can type a number – wvp Jun 06 '12 at 12:40