I would like to check if an entered e-mail adress is valid or not. I know IVY uses JSR 303 validations, but unfortunately there is no e-mail validation? Can anybody provide a small IVY project sample?

asked 17.02.2015 at 16:51

peter_muc's gravatar image

peter_muc
(suspended)
accept rate: 0%


Hi Peter,

i used following validater for the Inputfield

< p:inputText id="email" value="#{data.tmpEmailAddress}" validatorMessage="Invalid email format">
< f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
< /p:inputText>

hope that helps.

Roland

link

answered 18.02.2015 at 09:25

roland's gravatar image

roland
(suspended)
accept rate: 41%

edited 18.02.2015 at 09:28

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
9.4k31958

Thanks for your help Reguel! I have found an additional helpful link:

http://www.primefaces.org/showcase/ui/csv/custom.xhtml

link

answered 19.02.2015 at 11:58

peter_muc's gravatar image

peter_muc
(suspended)
accept rate: 0%

You can use bean validation of type regex to validat mail addresses. I've created a demo IAR here.

The approach is quite simple. I use a normal java bean with an annotated e-mail field. This java class is used on a JSF dialog and therefore annotations are automatically validated.

public class Person 
{
  /**
  * @see http://www.regular-expressions.info/email.html
  */
  @Pattern(message="mail address is invalid", 
        regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?")
  @NotNull(message="<%=ivy.cms.co(\"/ch.ivyteam.htmldialog.demo/BeanValidationDemo/notnull\")%>")
  private String email;

  public String getEmail() {
    return email;
  }
  public void setEmail(String email) {
    this.email = email;
  }

Bean validation compared to in view validation (as shown by roland) has an advantage. You can re-use the validation on every dialog where you use the bean without writing extra code. So define validation once, have a valid state everywhere...

link

answered 18.02.2015 at 09:27

Reguel%20Wermelinger's gravatar image

Reguel Werme... ♦♦
9.4k31958
accept rate: 70%

edited 18.02.2015 at 09:30

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×58

Asked: 17.02.2015 at 16:51

Seen: 7,050 times

Last updated: 19.02.2015 at 11:58