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.
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])