Email and date validation without regular expressions

November 28, 2008

I just discovered filter_var() –  very handy for validating form input, I’ve switched over from validating emails with regular expressions and I use this instead now:

filter_var($_POST[“email”],FILTER_VALIDATE_EMAIL)

… so now I don’t have to worry me getting the regexp wrong and rejecting emails when I shouldn’t. Nice. I used to validate date using regular expressions too, changed that too recently to use checkdate() (another new discovery, even though it’s been around since php4).

If only javascript had better built-in functionality for validating this stuff on the client side too I’d be laughing

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: