|
View:
New views
14 Messages
—
Rating Filter:
Alert me
|
|
|
Valudating common field typesHello,
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. 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. 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. Thanks. Sincerely, Yogesh _______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
|
|
Re: Valudating common field typesHi,
> 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 |
|
|
Re: Valudating common field typesYogesh Agashe wrote:
> Hello, > > 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. Welcome, was the same with me, except that I never really left beginner stage. > 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. > Thanks. > The only thing I would check is that the fields are not empty. The maximum length is set via the maxlength parameter in HTML and everything else qualifies as a valid name. I don't think you can reasonably script validation to make sure that the first name entered is "Dirk" and not "Dork". David _______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
|
|
Re: Valudating common field typesbe careful. don't just check if the field is NON empty. that's not good enough.
in English, you can reasonably assume the following to be true about names:
- must contain at least 1 letter [A-Za-z]
- may contain ' (apostrephe) and - (dash) and (space)
- shouldn't be longer than 40 characters.
- should not contain #s, or any other symbol, especially < (so ppl don't start entering html codes, js, etc)
Konstantin
On Mon, Oct 26, 2009 at 3:48 PM, David Krings <ramons@...> wrote: Yogesh Agashe wrote: _______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
|
|
Re: Valudating common field typesoh and also allow for . (periods)....
On Mon, Oct 26, 2009 at 4:06 PM, Konstantin K <kkrutoi@...> wrote:
_______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
|
|
Re: Valudating common field types
Hello Hans,
Thanks for the welcome. :) Okay, I use PCRE type functions for regular expressions so I think I can continue using them without worrying about the speed. Yes, I never thought if i had to support a different character sets. Thanks for pointing out the possibilities. Sincerely, Yogesh Hans Zaunere wrote: Hi, _______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
|
|
Re: Valudating common field typesHello David,
Thanks for the welcome. Yes, I am checking that they are not empty. Thanks for the feedback. Sincerely, Yogesh David Krings wrote: > Yogesh Agashe wrote: >> Hello, >> >> 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. > > Welcome, was the same with me, except that I never really left > beginner stage. > > > > 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. >> Thanks. >> > > The only thing I would check is that the fields are not empty. The > maximum length is set via the maxlength parameter in HTML and > everything else qualifies as a valid name. I don't think you can > reasonably script validation to make sure that the first name entered > is "Dirk" and not "Dork". > > David > _______________________________________________ > New York PHP Users Group Community Talk Mailing List > http://lists.nyphp.org/mailman/listinfo/talk > > http://www.nyphp.org/Show-Participation New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
|
|
Re: Valudating common field types
Hi Konstantin,
Thanks for the feedback. Right, So many cases to handle in there. I will also add minimum 2 characters to the list. Thanks, Yogesh Konstantin K wrote: oh and also allow for . (periods).... _______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
|
|
Re: Valudating common field typesOn Mon, Oct 26, 2009 at 4:16 PM, Yogesh Agashe <yogesh.agashe@...> wrote:
> Hi Konstantin, > > Thanks for the feedback. Right, So many cases to handle in there. I will > also add minimum 2 characters to the list. May I ask, what is the point of all of this? Who benefits from you imposing all sorts of piddly rules about what is in a name? Do you benefit? Why go to the extra effort to make your code only work for 99% of American English names. If you do nothing, your code will work for any name, and you will have more free time to do something worthwhile. BTW, I just checked my database, and I have 2 icelandic customers that don't even have last names on their credit cards. I am glad I don't do validation, because if I did, I probably would have lost those customers. Regards, -John Campbell _______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
|
|
Re: Valudating common field types> Thanks for the feedback. Right, So many cases to handle in there. I
> will also add minimum 2 characters to the list. That might not be correct, especially for Asian lastnames/etc... oh, minimum of 2, but you get my meaning... what if you will want to support a middle initial? :) End of the day, I wouldn't try to validate too much. Just protect your site more from a security perspective. Effectively, for all non-text area input, I don't allow whitespace except for a regular horizontal space. And for text-areas, well, it all depends :) H _______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
|
|
Re: Valudating common field typesOn Mon, Oct 26, 2009 at 4:16 PM, Yogesh Agashe <yogesh.agashe@...> wrote:
Some time ago I borrowed and stole and cobbled together this regex for a first name: /[^a-zA-Z\xC0-\xFF ]/ This is your whitelist approach. You test if the value contains anything other than this; if it doesn't, it's good. Min and max lengths have to be checked separately, though if you are really a ninja I think this could be made part of the regex. I allow space because there may be a 'Marie Christine' or some such who really wants the two parts regards as a single first name. The \x stuff allows a slew of chars found in Western European languages, so you're somewhat internationalized. If memory serves I think I got that from Daniel C. My surname validator is the same except that it permits ' (apostrophe). -- Demand health care for everyone: http://mobilizeforhealthcare.org/ -- David Mintz http://davidmintz.org/ _______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
|
|
Re: Valudating common field typesOn Mon, Oct 26, 2009 at 4:26 PM, John Campbell <jcampbell1@...> wrote:
Maybe you just want to protect users from their own mistakes, so they don't input Hen3ry where they mean Henry.
I guess it depends on the application and the type of data you expect. -- Demand health care for everyone: http://mobilizeforhealthcare.org/ -- David Mintz http://davidmintz.org/ _______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
|
|
Re: Valudating common field typesOn Mon, Oct 26, 2009 at 4:27 PM, Hans Zaunere <lists@...> wrote:
But it's nice to let them proof it. -- Demand health care for everyone: http://mobilizeforhealthcare.org/ -- David Mintz http://davidmintz.org/ _______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
|
|
Re: Valudating common field types
Ya, I got what you are saying. I think I was doing too much of it. Also
I did not think about the visitors from different continent than North
America.
Thanks, Yogesh Hans Zaunere wrote:
_______________________________________________ New York PHP Users Group Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk http://www.nyphp.org/Show-Participation |
| Free embeddable forum powered by Nabble | Forum Help |