New course! Every coder should learn Generative AI!
Try a free lesson+ 1
define conditions to make a defined variable acceptable.
create a function that returns an accepted value or an error if the argument is not accepted.
Look also at the "novalidate" html form attributes.
Your question is very generic: so is the answer.
giving more details in what you are trying to achieve will always benefit.