I am developing a logging system using ajax
this time in a very different way than one of my previous questions by making a few changes.
This time using json_encode
to personally receive the error messages in my file ajax
when receiving a correct answer through unn status
true
I perform a very different action than the erroneous answers through the status
false
.
My question is, how can I add more checks of the same action or the same data using the same technology used, although it is true that when sending input
empty fields, Ajax brings me the response, but there is no validation of emeil
any erroneous data can be received in the data table record.
How valid is the email, by status=>false
mentioning that the entered email is not valid, if so.
if (empty($_POST['email'])){
echo json_encode(['status'=> false, 'message'=> ["email" =>"Por favor ingresé su email."]]);
exit;
}
In the same way it is necessary to add other validations to the field password
, at the moment it is valid that both passwords must be the same, but I would need to add a minimum of characters of length password
of 6 and a maximum of 20 characters, between it it must have a special character , a digit or number, an uppercase letter, and a lowercase letter.
if($password_again !== $password){
echo json_encode(['status'=> false, 'message'=> ["password" =>"Las contraseñas no coinciden"]]);
exit;
}
Can you explain to me how I can perform this procedure, I can do it in a different way, but when using this same procedure status false
there must be another procedure and maybe even some recommendations.
You should rethink the way you return error messages.
It's okay if you have a single field
status
, but if you only have onemessages
then you should use it as an array so you can enter multiple messages instead of just one.Here is an example:
Perform email validations, including invalid email addresses:
algo@algo
, for this, we are going to use the expressionspreg_match
, without changing the subject of the question.You can add the expression from the same dependency, between a
else
Or at the same time, in the following way, since the base of the validations is to show only the error messages of the same.
Requirements of
Password
, through the same regular expression:Must be 8-20 characters
Other alternatives of different ways of using it.
You can use this PHP function to validate characters and structure: