Hi, > This is my first post to this NYPHP mailing list. So hello to everyone > and thanks for the thorough discussions which help a beginner developer > like me.
Hi Yogesh and welcome. > I have a simple question. I want to validate first and last name. I > assume that these are probably most common fields in any type of > registration forms on websites. > > When I validate these fields, I can't use ctype_alpha since these don't > allow ' as in O'Reilly or Last Name with white space in it. I have to > use a regular expression here. That's fine and I use it as well. Another > method is to find a single ' or space, trim it and then validate > remaining alphabet characters. RegEx is slower and even in new > filter_input, there is no way to validate these field types. I wouldn't worry too much about the speed of regex (I'd recommend pcre_* functions). > Is there any other way to validate first and last names. It will be nice > to have have inbuilt function for such commonly used field types. I will > like to know how people tackle these issue. But note that validating is all relative. What if you need to support various charsets? I typically just check for strings without newlines and non-printable chars. For international sites, obviously, there are some other loops involved. H _______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation