PHP validation class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
staar2
Forum Commoner
Posts: 83
Joined: Fri Apr 06, 2007 2:57 am

PHP validation class

Post by staar2 »

I need some validation class wich isn't big. Search from google but didn't find nofthing useful.
TY
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

validating what?
staar2
Forum Commoner
Posts: 83
Joined: Fri Apr 06, 2007 2:57 am

Post by staar2 »

OOps! Validatiting data from form post.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You could write a few small regexps.

Username (length 6-18):

Code: Select all

^[A-Za-z0-9_]{6,18}$
Email:

Code: Select all

^[^@\s]+@[^\.]+\.(?:[\w]{2,4}(?!\.)|[\w]{2}\.[\w]{2})$
I'm not too sure about my email regex and the whole RCC compliance thing though. :P
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

superdezign wrote:Email:

Code: Select all

^[^@\s]+@[^\.]+\.(?:[\w]{2,4}(?!\.)|[\w]{2}\.[\w]{2})$
I'm not too sure about my email regex and the whole RCC compliance thing though. :P
It's definitely not. :)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Hehe, figures. I should really read up on that one day.

Maybe today.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

superdezign wrote:Hehe, figures. I should really read up on that one day.

Maybe today.
No need... viewtopic.php?t=66712&highlight=validateemailformat
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

^_^

There's a lot of invalid characters.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I've come to the conclusion, however, that RFC-validating emails is usually useless in most real-world contexts. An approximation will usually do well.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

.. I already implemented it though. 8O

Should I rewrite my regex? (which I just realized is already here ^_^)
Post Reply