Reputation: 954
I would like to restrict specific domain to enter in my email form field using pattern.
<input type='email' name='email' pattern='' required/>
i want to restrict "mydomain.com
" not just .com/.org/.in
, to enter in my email field.
How i can do that using reg expression?
I know how i can allow specific domain using reg. but reverse is not working for me. sorry i m not good with reg expression
Thanks in advance
Upvotes: 0
Views: 2040
Reputation: 4010
You can use negative look aheads to handle validating against a string that is NOT followed by another string.
If you want to allow something.com
but not something.org
you can use \w*\.(?!org)
. This will match your something.
, but will fail when it is followed by org
. To add more cases to this, you can add extra negative look aheads in as needed IE: \w*\.(?!com)(?!org)(?!net)
.
I did some testing using some examples here.
Upvotes: 1