Last active
December 22, 2015 14:38
-
-
Save joshtronic/6486896 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Checks that all of the fields are present and not null | |
if (isset($_POST['username'], $_POST['email'], $_POST['password']) | |
&& !String::isEmpty($_POST['username'], $_POST['email'], $_POST['password'])) | |
{ | |
// Checks that the username is the correct format | |
if (strlen($_POST['username']) > 32) | |
{ | |
$message = 'Usernames may not be more than 32 characters.'; | |
} | |
elseif (!preg_match('/^[a-z0-9-]+$/i', $_POST['username'])) | |
{ | |
$message = 'Usernames may only contain alphanumeric characters or dashes.'; | |
} | |
elseif (substr($_POST['username'], 0, 1) == '-' || substr($_POST['username'], -1, 1) == '-') | |
{ | |
$message = 'Usernames may not start or end with a dash.'; | |
} | |
elseif (preg_match('/-{2,}/', $_POST['username'])) | |
{ | |
$message = 'Usernames may not have two or more dashes in a row.'; | |
} | |
// Checks that the email address is the correct format | |
elseif (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) | |
{ | |
$message = 'Your email address is invalid.'; | |
} | |
// Checks that the password is at least 8 characters | |
elseif (strlen($_POST['password']) < 6) | |
{ | |
$message = 'Passwords may not be less than 8 characters.'; | |
} | |
else | |
{ ... } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected $ajax = true; | |
protected $method = 'POST'; | |
protected $validate = array( | |
'username' => array( | |
'length:>:32' => 'Usernames may not be more than 32 characters.', | |
'regex:is:/[^a-z0-9-]+/i' => 'Usernames may only contain alphanumeric characters or dashes.', | |
'regex:is:/^(-.+|.+-)$/' => 'Usernames may not start or end with a dash.', | |
'regex:is:/-{2,}/' => 'Usernames may not have two or more dashes in a row.', | |
), | |
'email' => array( | |
'filter:email' => 'Your email address is invalid.', | |
), | |
'password' => array( | |
'length:<:8' => 'Passwords may not be less than 8 characters.', | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment