Extract generic form validation code