Skip to content

Instantly share code, notes, and snippets.

@arvindsvt
Created April 26, 2024 02:16
Show Gist options
  • Save arvindsvt/95f3fd683470196ec58aaa9455b0a314 to your computer and use it in GitHub Desktop.
Save arvindsvt/95f3fd683470196ec58aaa9455b0a314 to your computer and use it in GitHub Desktop.
validate
if(empty($data_to_db['user_name'])) {
$_SESSION['errors']['user_name'] = "User name is required";
}
if(empty($data_to_db['user_email'])) {
$_SESSION['errors']['user_email'] = "Email is required";
}
if( filter_var( $data_to_db['user_email'] , FILTER_VALIDATE_EMAIL) ) {
$_SESSION['errors']['user_email'] = "Email is required";
}
if (empty($data_to_db['password'])) {
$_SESSION['errors']['password'] = "Password is required";
}
if(strlen( $data_to_db['password'] ) < 8)
{
$_SESSION['errors']['password2'] = "Password must be more than 8 characters in length";
}
if( !(preg_match('#[0-9]#', $data_to_db['password'] ) ))
{
$_SESSION['errors']['password3'] = "Password must contain at least one number";
}
if (!preg_match('/([a-z]{1,})/', $data_to_db['password'] )) {
// atleast one lowercase letter
$_SESSION['errors']['password4'] = "Password must contain at atleast one lowercase letter";
}
if (!preg_match('/([A-Z]{1,})/', $data_to_db['password'] )) {
// atleast one uppercase letter
$_SESSION['errors']['password5'] = "Password must contain at least one uppercase letter";
}
if (!preg_match("/\W/", $data_to_db['password'] )) {
$_SESSION['errors']['password6'] = "Password should contain at least one special character";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment