{"id":13394928,"url":"https://github.com/mailcheck/mailcheck","last_synced_at":"2025-04-11T03:29:23.419Z","repository":{"id":2699519,"uuid":"3693021","full_name":"mailcheck/mailcheck","owner":"mailcheck","description":"Reduce misspelled email addresses in your web apps.","archived":false,"fork":false,"pushed_at":"2022-05-06T21:06:51.000Z","size":405,"stargazers_count":7956,"open_issues_count":43,"forks_count":465,"subscribers_count":160,"default_branch":"master","last_synced_at":"2024-10-29T11:22:54.768Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mailcheck.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-03-12T07:36:39.000Z","updated_at":"2024-10-28T15:43:48.000Z","dependencies_parsed_at":"2022-07-14T04:40:29.799Z","dependency_job_id":null,"html_url":"https://github.com/mailcheck/mailcheck","commit_stats":null,"previous_names":["kicksend/mailcheck"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailcheck%2Fmailcheck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailcheck%2Fmailcheck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailcheck%2Fmailcheck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailcheck%2Fmailcheck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mailcheck","download_url":"https://codeload.github.com/mailcheck/mailcheck/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248335213,"owners_count":21086538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T17:01:36.431Z","updated_at":"2025-04-11T03:29:23.386Z","avatar_url":"https://github.com/mailcheck.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Javascript","others","10. 表单处理","Email","JS/ES6"],"sub_categories":["Validation","10.1 表单验证(Form Validator)/表单提示"],"readme":"mailcheck.js\n=========\n\n[![TravisCI Build Status](https://secure.travis-ci.org/mailcheck/mailcheck.png?branch=master)](https://travis-ci.org/mailcheck/mailcheck)\n\nThe Javascript library and jQuery plugin that suggests a right domain when your users misspell it in an email address.\n\nmailcheck.js is part of the [Mailcheck family](http://getmailcheck.org), and we're always on the lookout for more ports and adaptions. Get in touch!\n\nWhat does it do?\n----------------\n\nWhen your user types in \"user@gmil.con\", Mailcheck will suggest \"user@gmail.com\".\n\nMailcheck will offer up suggestions for second and top level domains too. For example, when a user types in \"user@hotmail.cmo\", \"hotmail.com\" will be suggested. Similarly, if only the second level domain is misspelled, it will be corrected independently of the top level domain.\n\n![diagram](https://raw.githubusercontent.com/mailcheck/mailcheck/master/doc/example.png)\n\nSee it live in action [here](https://www.kickstarter.com/signup).\n\nInstallation\n------------\n\nFor instant use, download the minified library [mailcheck.min.js](https://raw.githubusercontent.com/mailcheck/mailcheck/d25dc9a119ca844bb35b1baf341cca0a634e4ac9/src/mailcheck.min.js) into your javascripts directory. [mailcheck.js](https://raw.githubusercontent.com/mailcheck/mailcheck/d25dc9a119ca844bb35b1baf341cca0a634e4ac9/src/mailcheck.js) is also available unminimised if you want to hack on it, or have your own minimizer.\n\n#### Bower ####\n\n```\n\u003e bower install --save mailcheck\n```\n\n#### Node/Browserify ####\n\n```\n\u003e npm install --save mailcheck\n```\n\nUsage with jQuery\n-----\n\nFirst, include jQuery and Mailcheck into the page.\n\n```html\n\u003cscript src=\"jquery.min.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"mailcheck.min.js\"\u003e\u003c/script\u003e\n```\n\nHave a text field.\n\n```html\n\u003cinput id=\"email\" name=\"email\" type=\"email\" /\u003e\n```\n\nNow, attach Mailcheck to the text field. You can declare an array of domains, second level domains and top level domains you want to check against.\n\n```html\n\u003cscript\u003e\nvar domains = ['gmail.com', 'aol.com'];\nvar secondLevelDomains = ['hotmail']\nvar topLevelDomains = [\"com\", \"net\", \"org\"];\n\nvar superStringDistance = function(string1, string2) {\n  // a string distance algorithm of your choosing\n}\n\n$('#email').on('blur', function() {\n  $(this).mailcheck({\n    domains: domains,                       // optional\n    secondLevelDomains: secondLevelDomains, // optional\n    topLevelDomains: topLevelDomains,       // optional\n    distanceFunction: superStringDistance,  // optional\n    suggested: function(element, suggestion) {\n      // callback code\n    },\n    empty: function(element) {\n      // callback code\n    }\n  });\n});\n\u003c/script\u003e\n```\n\nMailcheck takes in two callbacks, `suggested` and `empty`. We recommend you supply both.\n\n`suggested` is called when there's a suggestion. Mailcheck passes in the target element and the suggestion. The suggestion is an object with the following members:\n\n```js\n{\n  address: 'test',          // the address; part before the @ sign\n  domain: 'gmail.com',    // the suggested domain\n  full: 'test@gmail.com'  // the full suggested email\n}\n```\nMailcheck does not want to get in the way of how you can show suggestions. Use the suggestion object to display suggestions in your preferred manner.\n\n`empty` is called when there's no suggestion. Mailcheck just passes in the target element. It is a good idea to use this callback to clear an existing suggestion.\n\nUsage without jQuery\n--------------------\n\nMailcheck is decoupled from jQuery, so its usage without jQuery is almost identical.\n\nUsing the example from above, you would call `Mailcheck.run` instead.\n\n```html\n\u003cscript\u003e\nMailcheck.run({\n  email: yourTextInput.value,\n  domains: domains,                       // optional\n  topLevelDomains: topLevelDomains,       // optional\n  secondLevelDomains: secondLevelDomains, // optional\n  distanceFunction: superStringDistance,  // optional\n  suggested: function(suggestion) {\n    // callback code\n  },\n  empty: function() {\n    // callback code\n  }\n});\n\u003c/script\u003e\n```\n\nThe rest works similarly. In fact, the Mailcheck jQuery plugin just wraps `Mailcheck.run`.\n\nUsage on Node.js\n----------------\n\nIf you're running this on Node.js, you can just `require('mailcheck')` to get the `mailcheck` object, and call `run` on that:\n\n```js\nvar mailcheck = require('mailcheck');\n\nmailcheck.run({\n  // see 'usage without jQuery' above.\n});\n```\n\nDomains\n-------\n\nMailcheck has inbuilt defaults if the `domains`, `secondLevelDomains` or `topLevelDomains` options aren't provided. We still recommend supplying your own domains based on the distribution of your users.\n\n#### Adding your own Domains ####\n\nYou can replace Mailcheck's default domain/TLD suggestions by supplying replacements to `mailcheck.run`:\n\n```js\nMailcheck.run({\n  domains: ['customdomain.com', 'anotherdomain.net'], // replaces existing domains\n  secondLevelDomains: ['domain', 'yetanotherdomain'], // replaces existing SLDs\n  topLevelDomains: ['com.au', 'ru'] // replaces existing TLDs\n});\n```\n\nAlternatively, you can *extend* Mailcheck's global set of default domains and TLDs by adding items to `Mailcheck.defaultDomains` and `Mailcheck.defaultTopLevelDomains`:\n\n```js\nMailcheck.defaultDomains.push('customdomain.com', 'anotherdomain.net') // extend existing domains\nMailcheck.defaultSecondLevelDomains.push('domain', 'yetanotherdomain') // extend existing SLDs\nMailcheck.defaultTopLevelDomains.push('com.au', 'ru') // extend existing TLDs\n```\n\nCustomization\n-------------\n\nThe Mailcheck jQuery plugin wraps Mailcheck. The prime candidates for customization are the methods\n`Mailcheck.findClosestDomain` and `Mailcheck.stringDistance`.\n\nMailcheck currently uses the [sift3](http://siderite.blogspot.com/2007/04/super-fast-and-accurate-string-distance.html) string similarity algorithm by [Siderite](http://siderite.blogspot.com/). You can modify the inbuilt string distance function, or pass in your own when calling Mailcheck.\n\nSince Mailcheck runs client side, keep in mind file size, memory usage and performance.\n\nTests\n-----\n\nMailcheck is tested with [Jasmine](https://jasmine.github.io/). Run `npm test` from the command line to run the test suite. Alternatively, you can Load `spec/spec_runner.html` in your browser.\n\nContributing\n------------\n\nLet's make Mailcheck awesome. We're on the lookout for maintainers and [contributors](https://github.com/mailcheck/mailcheck/contributors).\n\nAnd do send in those pull requests! To get them accepted, please:\n\n- Test your code. Add test cases to `spec/mailcheckSpec.js`, and run it across browsers (yes, including IE).\n- Minify the plugin by running `grunt` in the Mailcheck directory (npm install should have installed a git pre-commit hook that takes care of this for you).\n\nUpcoming features, bugs and feature requests are managed in [Issues](https://github.com/mailcheck/mailcheck/issues).\n\nWho uses Mailcheck?\n-----------------------\n\n- [Dropbox](http://dropbox.com/)\n- [Hack Design](https://hackdesign.org/)\n- [Kicksend](http://kicksend.com/)\n- [Kickstarter](http://kickstarter.com/)\n- [Khan Academy](http://khanacademy.org/)\n- [Lyft](http://lyft.com/)\n- [Minecraft](http://minecraft.net/)\n- [SB Nation](http://sbnation.com/)\n- [The Verge](http://theverge.com/)\n\nDo you use Mailcheck? [Tweet me](http://twitter.com/derrickko) your link.\n\nRelated Links\n-------------\n\n- [Official Mailcheck Ports](https://github.com/mailcheck/)\n- [Two ways to reduce bounced welcome emails](http://blog.postmarkapp.com/post/19685472721/two-ways-to-reduce-bounced-welcome-emails) by [Postmark](http://postmark.com)\n- [MooTools port](https://github.com/DimitarChristoff/mailcheck) by [Dimitar Christoff](https://github.com/DimitarChristoff)\n- [WordPress Plugin](https://github.com/bmoredrew/mailcheck-wordpress-plugin/) by [Drew Poland](https://github.com/bmoredrew)\n- [WordPress e-Commerce Plugin](http://wordpress.org/extend/plugins/e-commerce-mailcheck/)\n- [Mailcheck for Drupal](http://drupal.org/project/Mailcheck) by [Martin Elvar](https://twitter.com/MartinElvar)\n\nCore Team\n-------\n\n- Derrick Ko, [@derrickko](http://twitter.com/derrickko). Created Mailcheck.\n- Wei Lu, [Hive](https://www.hivewallet.com/), [@luweidewei](http://twitter.com/luweidewei).\n\nLicense\n-------\n\nReleased under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailcheck%2Fmailcheck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmailcheck%2Fmailcheck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailcheck%2Fmailcheck/lists"}