@@ -0,0 +1,958 @@
+package com.pollistics.models.validators;%0A%0Aimport org.springframework.validation.Errors;%0Aimport org.springframework.validation.Validator;%0Aimport com.pollistics.models.*;%0A%0Apublic class UserValidator implements Validator %7B%09%0A%09@Override%0A%09public boolean supports(Class%3C?%3E clazz) %7B%0A%09%09return clazz.isInstance(User.class);%0A%09%7D%0A%0A%09@Override%0A%09public void validate(Object target, Errors errors) %7B%0A%09%09User user = (User) target;%0A%09%09if(!user.getUsername().matches(%22%5E(?=.%7B3,20%7D$)(?!%5B_.%5D)(?!.*%5B_.%5D%7B2%7D)%5Ba-zA-Z0-9._%5D+(?%3C!%5B_.%5D)$%22)) %7B%0A%09%09%09errors.rejectValue(%22username%22, %22invalid.username%22, %22Username has to be 3 to 20 characters and contain only letters, number and dots or underscores.%22);%0A%09%09%7D%0A%09%09if(!user.getPassword().matches(%22%5E(?=.*%5B0-9%5D)(?=.*%5Ba-z%5D)(?=.*%5BA-Z%5D)(?=%5C%5CS+$).%7B8,%7D$%22)) %7B%0A%09%09%09errors.rejectValue(%22password%22, %22invalid.password%22, %22Password has to be at least 8 characters long and needs to contain at least one uppercase letter, one lowercase leter and one number%22);%0A%09%09%7D%0A%09%7D%0A%7D%0A

Add validator for user object