Accept email from a particular domain

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
I am trying to setup a site, and want people with only "@gmail.com" should be able to register or buy a product, any help on this would be appreciated.
6 years ago
You need to add RegularExpression at Nop.Web > Models > Customer> RegisterModel


[NopResourceDisplayName("Account.Fields.Email")]
[RegularExpression(@"^[a-zA-Z0-9._%+-]+(@gmail\.com)$", ErrorMessage = "Registration limited to gmail only.")]
[AllowHtml]
public string Email { get; set; }
6 years ago
Thanks, will implement this and let you know.
6 years ago
It works thanks a lot, any case I want to add one more domain along with gmail.com let's say yahoo.co.uk, in that case, can you tell what needs to add? also is the wildcards allowed for example yahoo.*.*?
6 years ago
Divyang wrote:
You need to add RegularExpression at Nop.Web > Models > Customer> RegisterModel


[NopResourceDisplayName("Account.Fields.Email")]
[RegularExpression(@"^[a-zA-Z0-9._%+-]+(@gmail\.com)$", ErrorMessage = "Registration limited to gmail only.")]
[AllowHtml]
public string Email { get; set; }


I figured out how to add multiple domains, thank so much for your support, have a great day ahead.

Thanks
Kakoli
6 years ago
kakoli wrote:

I figured out how to add multiple domains, thank so much for your support, have a great day ahead.


Hey Kakoli,

Glad I could help, and that's great you found the solution for multiple domains, but it would be more better to share your thoughts and implementation with other community member so in future it will helps other members too!
6 years ago
Yes sure, I used following code.

[NopResourceDisplayName("Account.Fields.Email")]
[RegularExpression(@"^[a-zA-Z0-9._%+-]+@(gmail\.com|yahoo\.com|yahoo\.co.uk)$", ErrorMessage = "Registration limited to gmail amd yahoo only.")]
[AllowHtml]
public string Email { get; set; }

Wild card didn't work when I used yahoo\.*.*
6 years ago
kakoli wrote:

Wild card didn't work when I used yahoo\.*.*

Hey Kakoli,

For any regex expression, you need to understand what does each expression mean.

Let see, your regex is seems like ^[a-zA-Z0-9._%+-]+@(gmail\.com|yahoo\.*.*)$

* Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
.*
matches any character (except for line terminators)


So, if you want to use all domain with yahoo(.com, .au, .uk, .in etc.), I think your regular expression would be
^[a-zA-Z0-9._%+-]+@(gmail\.com|yahoo\.\w+)

I haven't checked with any project but it should work.

Advice: you can use online regex checker https://regex101.com/ before implementation, it will save your time!

Hope this helps!
6 years ago
Awesome, yes it did work, and learned something new thanks a ton.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.