I'm using yup for validating my react form.
My problem is :
I have the below schema for validating an input field.
object().shape({
firstname: string()
.required('First Name is required')
.test('length', 'First Name must have more than 1 character', (value) => {
console.log(value && value.length < 2 ? true : false);
return value && value.length < 2 ? true : false;
})
.test('alphabets', 'Name must only contain alphabets', (value) => {
console.log(!/^[A-Za-z]+$/.test(value));
return !/^[A-Za-z]+$/.test(value);
})
});
When I enter a single character it shows Name must only contain alphabets error message and when I try to type more characters it shows First Name must have more than 1 character error message.
What should I do wrong?
Anyone, please help me with this?