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

Leave a Reply