Home › Forums › Back End › Sign up form › Re: Sign up form
May 26, 2011 at 1:41 am
#75287
ddliu
Member
The if scope is just a simple validation which means that every field should not be empty.
If any field not input, the script will quit and show an error message “Invalid data”.(die will stop the script, and the script will not be continued anymore)
For more complex validation, you should change this scope.
For example, to check the email, you may use regular expression; you may also limit the string length of first name and last name.
I’ve created a gist here: https://gist.github.com/f86c0424202c03be8d79
//validate first name
if(strlen($form_data)>30)
{
die('First name too long');
}
//validate last name
if(strlen($form_data)>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)
{
die('Invalid email address');
}