How do i make my function return ture or false ? #196
-
Hi, I am working on form validation and i have quick question but before that i would like to present my Pseudocode
now, validate function does the job and shows all kind of error if there are any. However I want validate function to return true or false so that i can show a success message along with submitting the values. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
How I understood your query is, that you want to have a consolidated return type for all your validations. const validateEmail = (emailvalue) => {
if emai is not valid
shows error
return false
else
hide error
return true
}
const comparePassword =(pass, confirmPass)=>{
if passwords do not match
shows error
return false
else
hide error
return true
}
const validate=(value)=>{
checks if values are empty
shows error
return true
else
hide "field can't be empty error"
return (validateEmail(email) && confirmPassword(pass,confirmPass))
}
const submitHandle = (e)=>{
e.preventDefault();
if(validate(value)){
submit the input values
print success message
clear the inputs
}
} |
Beta Was this translation helpful? Give feedback.
-
Thanks, this helped me a lot |
Beta Was this translation helpful? Give feedback.
How I understood your query is, that you want to have a consolidated return type for all your validations.
Going by the above understanding, you can prepare your return type from the core of the stack. A simple tweak to the above logic would be