Skip to content
Snippets Groups Projects
Commit b2279806 authored by Timo Jeremy Pinzauti's avatar Timo Jeremy Pinzauti
Browse files

Control angelegt und erste Versuche zur E-Mail Validierung

parent eaa09184
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ import com.vaadin.ui.Panel;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import org.s4s.services.util.EmailValidator;
/**
* Created by Max-Desktop on 16.05.2017.
......@@ -25,6 +26,7 @@ public class ContactView extends TemplateView{
setMargin(true);
final TextField tfEMail = new TextField("E-Mail");
tfEMail.addValidator(new EmailValidator());
final TextField tfBetreff = new TextField("Betreff");
final TextArea taNachricht = new TextArea("Ihr Anliegen");
final Button bSenden = new Button("Senden", FontAwesome.SEND);
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.s4s.process.control;
/**
*
* @author synot
*/
public class ContactControl {
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.s4s.services.util;
import com.vaadin.data.Validator;
/**
*
* @author synot
*/
public class EmailValidator implements Validator {
/**
* Tests if the given value is valid
* @param value the value to test
*/
public boolean isValid(Object value) {
try {
validate(value);
} catch (Validator.InvalidValueException ive) {
return false;
}
return true;
}
/**
* Validates
* @param value the value to test
*/
public void validate(Object value) throws Validator.InvalidValueException {
// Here value is a String containing what *should* be an e-mail address
if (value instanceof String) {
String email = (String)value;
// Match the email string against a (simplistic) regular expression matching e-mail addresses
if (!email.matches("^[_\\w\\.\\-]+@[\\w\\.-]+\\.[a-z]{2,6}$"))
throw new Validator.InvalidValueException("The e-mail address provided is not valid!");
}
}
}
Please add your static resources here
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment