How to validate full name?
full name contains a space only in the middle
@feira While I don't know of a way with this library, (Maybe open a PR to add that validation) you can do something like:
let fullName = "John Gill"
return (fullName ? fullName.split(" ").length : 0) === 2;
console.log(check === 2);
This will take care of double spaces leading and trailing spaces as well. You will have issues when it comes to "John Gill III" or other weird names that may be spaced or have Jr.'s, ect. You Can add a dropdown for these people to select from like many sites do.
How about adding this as a new validator in the package? This is must needed validation for any web project.
I came with this solution and it validates the full name of first name and last name.
validateFullName = (name) => {
const fullName = name.split(" ");
let isValid = false;
fullName.length <=2 ? (
isValid = validator.isAlpha(fullName[0]) && validator.isLength(fullName[0],{min:3,max:30}),
fullName[1] ? isValid = validator.isAlpha(fullName[1]) : ''
) : '';
return isValid;
}