SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbee - help with validating last name to allow apostrophe

    newbee needs a boost in how to validate a last name like O'Neal or O'Brien to allow the apostrophe to included?

    That's all, folks Thanks

  2. #2
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One important thing to consider first - is it possible that a user will enter non-english characters?

    If it's only for English letters and apostrophies, then its very easy.

  3. #3
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bankruptcy office in USA... clients of all nationalities... predominately US, Russian, and Spanish/Mexican names.

  4. #4
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Validated as in "Able to put this in the Database"? If that's the case, parameterize your SQL, and you'll be good to go.

  5. #5
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since court filings use English letters only, you can use this to test for valid name:
    if(preg_match("/[^a-zA-Z\s'-]+/", $string)){
    exit('BAD');
    }
    // continue your script

  6. #6
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to all for the quick response ...

    Closed!

  7. #7
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    @Sharedlog.com, are you stating that foreign letters are invalid?

    You shouldn't disallow those letters, it's wrong to do so. What about people's names, or names of a foreign language?

    Instead, use MySQL_Real_Escape_String to allow the apostrophe etc in the name (You should do this to all MySQL input anyway unless you are using a library like PDO which doesn't require it). Then make sure you're using a character encoding which supports a vast range of characters, such as UTF-8 or UTF-16.

    That way you allow input in without appearing unprofessional - and when dealing with court cases, being unprofessional and changing peoples' names so that they work with your broken system could be enough to bring a real court case upon your site.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  8. #8
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    @Sharedlog.com, are you stating that foreign letters are invalid?

    You shouldn't disallow those letters, it's wrong to do so. What about people's names, or names of a foreign language?

    Instead, use MySQL_Real_Escape_String to allow the apostrophe etc in the name (You should do this to all MySQL input anyway unless you are using a library like PDO which doesn't require it). Then make sure you're using a character encoding which supports a vast range of characters, such as UTF-8 or UTF-16.

    That way you allow input in without appearing unprofessional - and when dealing with court cases, being unprofessional and changing peoples' names so that they work with your broken system could be enough to bring a real court case upon your site.
    I am saying that court filings in the US are done in English letters only. Even foreign names are spelled using English-only letters and that's why I suggested this regex.

  9. #9
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks so much ... it's amazing how much I've learned from you'all ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •