I have one input where the user writes her/his first and last name. I need to validate if both first and second name start with capital letters. Also need to handle more than two names.
I've tried this in my validation object. I realize that I get a if for each element while mapping, not sure how to write this correctly.
nameCheck(value){
let name = value.split(" ");
name?.map(element => {
if(name?.length > 0 && element[0] === element[0].toUpperCase()){
return true
}
else{
return false
}
}
)
}
I'm calling it like this:
const isValidName = validate.nameCheck(form.creator)
console.log(isValidName)
Here isValidName ends up undefined. All my other validation-checks are simple if-statements which works fine.
Any idea how to tackle this?