-1

I'm using jQuery Validation Plugin and I need to prevent that some spam addresses stop sending recurrent leads.

Tried Google and reading the plugin documentation, but I'm a beginner in JS, so I couldn't find anything I needed.

P.S. Not talking about invalid email addresses but recurrent valid email addresses.

Sparky
  • 98,165
  • 25
  • 199
  • 285
Dico Didiraja
  • 63
  • 1
  • 6
  • the only way to check if an email is valid is to send something to it and then make the user open the email and get that out. It is a horrible user experience , but most sites do it because it is the only way – Scott Selby Apr 05 '17 at 21:15
  • 1
    Please read [ask]. Key phrases: "Search, and research" and "Explain ... any difficulties that have prevented you from solving it yourself". In other words, at least try and write some code. – Heretic Monkey Apr 05 '17 at 21:24
  • Also, please search SO before posting. Thanks. – Sparky Apr 05 '17 at 22:27
  • @MikeMcCaughan I searched through google, github foruns and SO but didn't find exactly what I was lookig for, **as I said, I'm a beginner**. – Dico Didiraja Apr 06 '17 at 14:22
  • @Sparky First read the coment above. Anyway, thelinks attached probably will help, thanks! – Dico Didiraja Apr 06 '17 at 14:23

2 Answers2

1

Please keep in mind that you should always double check user input serverside. Malicious users will always be able to bypass rules that are set clientside. Also, by doing it in JavaScript, you are disclosing your list of banned emails, and making it easier for hackers to see what they should do to bypass your rules.

That being said, you can load jQuery Validate's Additional methods plugin and use addMethod to create your own rules:

// Banning domains
var bannedDomains = ["spam.com", "junk.com"];

$.validator.addMethod('domainNotBanned', function(value, elem, param) {
  var domain = value.split('@')[1];
  return bannedDomains.indexOf(domain) < 0;
}, 'Emails from this domain are not allowed.');

// Banning specific addresses
var bannedEmails = ["mean@hacker.com", "kim.kardashian@gmail.com"];

$.validator.addMethod('emailNotBanned', function(value, elem, param) {
  return bannedEmails.indexOf(value) < 0;
}, 'This email address is banned.');

// Applying these rules
$('#myForm').validate({
  rules: {
    email: {
      required: true,
      email: true,
      domainNotBanned: true,
      emailNotBanned: true
    }
  }
});

// Just for the demo
$('#myForm').on('submit', function(e) {
  e.preventDefault();
  alert("This email is valid.");
  return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/additional-methods.min.js"></script>

<form id="myForm" name="myForm" action="#" method="POST">                                                                                                                                                                                                                     <style>#email-error { display: block; color: red; }</style>
  <label for="email">Email: </label>
  <input id="email" name="email" type="email" minlength="6"/><br>
  <input type="submit" value="Submit">
</form>
blex
  • 24,941
  • 5
  • 39
  • 72
-1

You can create a table in your DB to save the emails and domains that you don't want and check them before to do the next step.

aarkerio
  • 2,183
  • 2
  • 20
  • 34