Allow only specific email address' domain to register through JQuery (preferably)

前端 未结 2 657
故里飘歌
故里飘歌 2020-12-18 17:18

I am trying to make registration form within which I want to register only with specific domains\' emails. For e.g. I want to register only the emails which are from the com

相关标签:
2条回答
  • 2020-12-18 17:39

    An email is only going to contain one @ so you could split the input value and take the second part

    str = str.split('@').slice(1);
    

    then simply check if that is in your acceptable list

    var allowedDomains = [ 'x.com', 'y.com', 'z.com' ];
    
    if ($.inArray(str[0], allowedDomains) !== -1) {
        //acceptable
    }else{
        //not acceptable
    }
    

    here is a working example in a jsfiddle: http://jsfiddle.net/UwmYK/2/ just type in the email and click run.

    0 讨论(0)
  • 2020-12-18 17:52

    What if you have the input textbox only accept the first part of an email address and then have a select box that only has the email domains you want to allow for the user to select from?

    0 讨论(0)
提交回复
热议问题