I have this js, and this html:
$(document).on('click', '.validar', function (event) {
event.preventDefault();
var cantidad = 0;
var obj = {
"correo": $(".txtEmail").attr("id")
};
$.each(obj, function (identificador, value) {
cantidad = ($.onlyData("#" + value));
if (cantidad > 0) {
toastr["error"]("Este " + identificador + " ya se encuentra registrado!");
} else {
$("#msform").submit();
}
});
});
<div class="modal fade" id="modalNewClient" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Nuevo cliente</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<?php
echo $this->Form->create('Client', array('class' => '', 'id' => 'msform'));
?>
<div class="input-group">
<?php
echo $this->Form->input('contact', array('label' => array('text' => " "),
'placeholder' => 'Danos tu nombre',
"required" => "true",
"minlength" => "5",
"maxlength" => "",
'class' => 'form-control-custom color-input validLength txtContact lang prettyName',
'key' => 'txtContact'));
?>
</div>
<div class="input-group">
<?php
echo $this->Form->input('company', array('label' => array('text' => " "),
'placeholder' => '¿Para que marca vamos a trabajar?', "required" => "true",
"minlength" => "3",
"maxlength" => "",
'data-sql' => "company-Client",
'class' => 'form-control-custom color-input validLength txtClient lang prettyName',
'key' => 'txtClient'));
?>
</div>
<div class="input-group mb-3">
<?php
echo $this->Form->input('email', array('label' => array('text' => " "),
'placeholder' => 'Correo electronico',
"data-DB" => "email",
"required" => "true",
"minlength" => "5",
'data-sql' => "username-User",
"maxlength" => "",
'class' => 'form-control-custom color-input validLength prettyName txtEmail lang validEmail',
'key' => 'txtEmail'));
?>
</div>
<div class="input-group mb-3">
<?php
echo $this->Form->input('phone', array('label' => array('text' => " "),
'placeholder' => 'Celular', "minlength" => "7", "required" => "true", "maxlength" => "10", 'class' => 'form-control-custom color-input validLength txtPhone blockLetter lang', 'key' => 'txtPhone'));
?>
</div>
<?php echo $this->Form->end(array('label' => 'Guardar cliente', 'class' => 'validar')) ?>
</div>
</div>
</div>
the thing is that that js, validates if a field already exists in the database, but I do not know if there is any way to activate, the automatic validations of html5 from the js, on the internet I found this: $("#elemento").checkValidity();
but it did not work, I was thinking about something $("#formId").checkRequired();
or something like that, but I could not find anything
those are the validations of html5 and what I want is to activate them from jquery that is to say with some function to tell you to do the validations that normally hacel the html5 when giving a submit