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?
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?
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).
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