1 year ago

Best practice for validation and dry principle

Posted 1 year ago by nabilunfarhanun

What I read from the internet is it is good practice to validate both in front end and back end. Front end validation is needed for user friendliness. And back end validation is needed for security.

However how can I follow the dry principle while doing validation in both end?

For example, suppose, I have a form where it will accept password. And the password minimum length is 6. I did the back end validation with form controller and the front end validation with javascript.

However, if somehow the minimum length is changed to 8 then I need to change the length in two places. One is in back end; another in front end. Isn't it violating the dry principle? How can I manage this in such a way that I would need to change in only one place? What is the best practice in this case?

Please sign in or create an account to participate in this conversation.