User registration problem using java regex JUnit test, exception handling validate and refactor the code