Search code examples
javaregexemailspring-roo

Regular Expression for Email in Spring Roo


I am using Spring Roo and am having difficulty implementing the regular expression for the email field so that only properly formatted emails can be implemented into the field. When I run Tomcat and test the application using a local host I get a message saying

Enter a valid email

and this message appears everytime a "." is entered or if there is a space anywhere.

The current regex I am using is:

"^[_A-Za-z0-9-\\\\+]+(\\\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\\\.[A-Za-z0-9]+)*(\\\\.[A-Za-z]{2,})$"

Can anyone help me figure out what I am doing wrong? Is it an issue with Spring Roo or am I just using the wrong regex?


Solution

  • Try to use regex written and debugged by somebody else.

    Here are the examples:

    Using a regular expression to validate an email address

    http://www.regular-expressions.info/email.html

    http://commons.apache.org/proper/commons-validator/