This is a discussion on Accent characters in regexp within the alt.comp.lang.php forums, part of the PHP Programming Forums category; So I had this 'nifty' piece of regexp that would check for valid names. 'Had' I say untill I discovered ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
So I had this 'nifty' piece of regexp that would check for valid names.
'Had' I say untill I discovered that it does not accept any accented character like ë,é etc. I've been looking all over the place but cannot find a clear answer as to the best solution for this problem. The only solution that I get working sofar is by simply adding all possible accent characters to the regexp, but I would assume there would be a more generic solution for this ?? Anyway: below is what I have now, and it allows for a 'ë' in a string. The only solution? Or is there indeed a better way? PHP code: define("VALID_NAME","^([A-Z]{1})([a-zA-Zë\s \-]+)([a-z])$"); Thanks for any light on this matter. John |
|
|||
|
Laiverd.COM wrote:
> Anyway: below is what I have now, and it allows for a 'ë' in a > string. The only solution? Or is there indeed a better way? > You can use the "w" character class, which matches both accented and normal characters, as well as the underscore: print preg_match('/\w/', 'ë'); // 1 As it appears that you only want to allow for spaces and hyphens, you could do something like the following: $word = 'éìë-'; print !preg_match('/_/', $word) && preg_match('/^[\w\s-]+$/', $word); // 1 JW |