Skip to content

Instantly share code, notes, and snippets.

@ddliu
Created May 26, 2011 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddliu/f86c0424202c03be8d79 to your computer and use it in GitHub Desktop.
Save ddliu/f86c0424202c03be8d79 to your computer and use it in GitHub Desktop.
Do an extra validation on the form data
<?php
//validate first name
if(strlen($form_data['first_name'])>30)
{
die('First name too long');
}
//validate last name
if(strlen($form_data['last_name'])>30)
{
die('Last name too long');
}
//validate email
if(!preg_match('#^[a-z]([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$#i',$form_data['email'])
{
die('Invalid email address');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment