0

Possible Duplicate:
Regex to validate names

I am developing a site.In that i want to validate the users name that is their first name and last name.Names will also contain letters like ó

I now validate using

if(!preg_match("/[a-zA-Z]+$/",$value))
{
echo "Invalid characters";
}

How do i validate the special characters? Friends i meant special characters like ó . I want this available in the name . But take off the letters like @,#,$

Community
  • 1
  • 1
harikrishnan.n0077
  • 1,927
  • 4
  • 21
  • 27
  • 7
    Names are very complex. You'd be best off just checking that *something* has been entered. A white list won't work. – Quentin Nov 28 '12 at 13:52
  • Regex ain't suitable for first and last names, poor *Mr. O'Shea*. Just strip off harmful stuff. FWIW, [check this](http://stackoverflow.com/questions/8923729/checking-for-diacritics-with-a-regular-expression). – moonwave99 Nov 28 '12 at 13:54
  • @Quentin i would like to show their name to other users how could i show if it contain letters like @,#,$ etc. – harikrishnan.n0077 Nov 28 '12 at 13:55
  • @harikrishnan.n0077 — `

    My name is J@k Ca$h

    `. (Odds aren't too unfavourable that a rapper somewhere really is using that name).
    – Quentin Nov 28 '12 at 13:57
  • Who says that someone didn't name their child using $, #, @ etc? People are crazy and they do dumb stuff all day long, you can't rule anything out and as Quentin said - names are *very* complex. There is no rule about naming someone, you can literally be named using 25 000 spaces. – N.B. Nov 28 '12 at 13:57
  • There *are* rules about naming people, but they aren't globally implemented rules, so you can't make your system depend on them. – Quentin Nov 28 '12 at 13:58
  • You can probably disallow characters like `@` and `#`, 99.999999% of people probably won't have those in their names. Anything beyond that is pretty open though, names contain anything from `-` over `'` to `ó` and `雅`. – deceze Nov 28 '12 at 13:59
  • See what facebook does it does not allow @ # $ and allows ó .What about that? – harikrishnan.n0077 Nov 28 '12 at 14:01
  • So you want a regex that allows anything but `@#$`? `/^[^@#$]+$/` – deceze Nov 28 '12 at 14:11

0 Answers0