I would like to only allow email addresses which are valid and non public email addresses eg gmail,yahoo, hotmail etc.
Can anyone help me out check for this? Im guessing i would need to use a regular expression but not sure if there is an easier way
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you only need to filter on the top level domain, then you could use something like this:
This will only validate email address ending with
.edu,.gov, or.mil. For instance,Note: these will all assume that the regex option of
Ignore Caseis turned on.If you’d also like to allow for two-letter top level domain country codes, like
.fror.ca, you could add an expression for that like this:If instead you want to exclude the “big three” email hosts, you could use something like this:
(this uses look-ahead assertion with the
(?!)“match if suffix is not present” grouping) Examples:More regex examples for email address validation can be found here.