In addition to serverside validation I want to have some clientside validation (javascript/jquery) for an email input field accepting only emails where its address is at least 3 characters long and its tld at least 2 chararacters.
As of right now I'm checking the whole Email like this:
html:
<input type="email" name="email" placeholder="E-Mail" class="form-control" id="chatemail">
javascript:
var re_email = new RegExp(/^[a-zA-Z0-9\_\.\-]+@[a-zA-Z0-9\-]+(?:\.[a-zA-Z]+)$/);
var is_email = re_email.test($('#chatemail').val());
// and its length like this:
$('#chatemail').val().length > 5
But in addition how can I check that the email ending e.g. @gmx.de
... that the 'gmx' is at least 3 digits long and the the 'de' is at least 2 digits long? So what I don't want is that somebody can type in @g.d or @gm.c ... and stuff like that ...
I tried to split the regex ... but my attempts doesn't work ...
var re_email_01 = /^[a-zA-Z0-9\_\.\-]$/;
var re_email_02 = /^@[a-zA-Z0-9\-]$/;
var re_email_03 = /^(?:\.[a-zA-Z]+)$/;
var re_email = new RegExp(re_email_01+'+'+re_email_02+'+'+re_email_03);
I also tried this ...
var re_email = new RegExp(/^[a-zA-Z0-9\_\.\-]+@[a-zA-Z0-9\-]{3,}+(?:\.[a-zA-Z]{2,}+)$/);