what will be regular expression for email with custom domain in parsley validation

193 views Asked by At

I have a form on which I want to apply parsley validation. I want to allow only email with domain @ciit-atk.edu.pk but I don't have a regex for it that will work with parsley validation. The sample email is [email protected] and any other email not having the same domain will not be accepted. I don't want a generic regex, I need a regex for this specific domain that will work with parsley validation.

<input type="email" class="form-control" name="email" placeholder="Email..." required data-parsley-pattern="" data-parsley-trigger="keyup" >

The regex will go in data-parsley-pattern field. I have this regex "^[\w-\._\+%]+@(ciit-atk.edu.pk)" but it's not working.

1

There are 1 answers

1
sonEtLumiere On

Try this:

let emailTrue = '[email protected]';
let emailFalse = '[email protected]';

let emailRegex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@(ciit-atk.edu.pk)$/;
    
console.log(emailRegex.test(emailTrue));
console.log(emailRegex.test(emailFalse));