Angular2: how to add validator and exclude required
<p>I created a custom validator to check email addresses filled by users. Anyway the email field is not required, but if I add my validator it includes <code>required</code> as well.</p>

<p>Here is my form in the <code>constructor</code> of my component class:</p>

<pre><code>    this.myForm = fb.group({
        'name': [''],
        'surname': [''],
        'username': ['', Validators.required],
        'email': ['', validateEmail]
    });
</code></pre>

<p>Email field is not required, but if users doesn't fill it, the form doesn't get validated. At the same time if users fill it, I want that the email validation is applied.</p>

<p>Here is my email validator:</p>

<pre><code>export function validateEmail(c: FormControl) {
    var EMAIL_REGEXP = /^(|(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6})*$/i;

    return EMAIL_REGEXP.test(c.value) ? null : {
        validateEmail: {
            valid: false
        }
    };
}
</code></pre>

<p>I could edit my custom validator to accept empty strings, but I think this is not the right way to solve my problem.</p>

<p>Do you have a better idea?</p>