I have the following function in javaScript
:
function teste(ctrl) {
var str = ctrl.value;
var str = str.split(" ");
if (str.every(isBigEnough) && str.length >= 2) {
alert(true);
} else {
alert(false);
}
}
function isBigEnough(element, index, array) {
return element.length > 1;
}
<input id="nome" name="nome" type="text" placeholder="Nome completo" required onchange="teste(this)">
I want to replicate it in php
to have this validation also in back-end
There is a function in php similar, array_walk
only I am not getting it yet.
It would be something like:
function isBigEnough($item, $key) {
return strlen($item) >= 2;
}
function validaNome($value) {
var $str = $value;
var $str = explode(" ",$value);
if (array_walk($str, 'isBigEnough') && count($str) >= 2) {
return true;
}else{
return false;
}
}