Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex for email domain after @

Let’s say I have email:

testmail@test.com

In my project (JavaScript) into input field user will provide only email domain (after @). So, in this case, I need only test.com.

All I want to do is to check if it has pattern of domain, I mean it seems like this – x.y where x and y could contain any number of letters (without numbers) separated by a dot.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I create this regex?

>Solution :

You can use a positive lookbehind for the @ and match the letters and dots after it: (?<=@)[a-z\.]+[a-z]

const regex = /(?<=@)[a-z\.]+[a-z]/i;
const testString = "testmail@test.com";

console.log(testString.match(regex)[0])

regex101

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading