Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Validator | Description
**isDecimal(str [, options])** | check if the string represents a decimal number, such as 0.1, .3, 1.1, 1.00003, 4.0, etc.<br/><br/>`options` is an object which defaults to `{force_decimal: false, decimal_digits: '1,', locale: 'en-US'}`<br/><br/>`locale` determine the decimal separator and is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa', 'fa-AF', 'fa-IR', 'fr-FR', 'fr-CA', 'hu-HU', 'id-ID', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pl-Pl', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN']`.<br/>**Note:** `decimal_digits` is given as a range like '1,3', a specific value like '3' or min like '1,'.
**isDivisibleBy(str, number)** | check if the string is a number that's divisible by another.
**isEAN(str)** | check if the string is an EAN (European Article Number).
**isEmoji(str)** | check if the string is contains an Emoji.
**isEmail(str [, options])** | check if the string is an email.<br/><br/>`options` is an object which defaults to `{ allow_display_name: false, require_display_name: false, allow_utf8_local_part: true, require_tld: true, allow_ip_domain: false, domain_specific_validation: false, blacklisted_chars: '', host_blacklist: [] }`. If `allow_display_name` is set to true, the validator will also match `Display Name <email-address>`. If `require_display_name` is set to true, the validator will reject strings without the format `Display Name <email-address>`. If `allow_utf8_local_part` is set to false, the validator will not allow any non-English UTF8 character in email address' local part. If `require_tld` is set to false, e-mail addresses without having TLD in their domain will also be matched. If `ignore_max_length` is set to true, the validator will not check for the standard max length of an email. If `allow_ip_domain` is set to true, the validator will allow IP addresses in the host part. If `domain_specific_validation` is true, some additional validation will be enabled, e.g. disallowing certain syntactically valid email addresses that are rejected by GMail. If `blacklisted_chars` receives a string, then the validator will reject emails that include any of the characters in the string, in the name part. If `host_blacklist` is set to an array of strings and the part of the email after the `@` symbol matches one of the strings defined in it, the validation fails.
**isEmpty(str [, options])** | check if the string has a length of zero.<br/><br/>`options` is an object which defaults to `{ ignore_whitespace:false }`.
**isEthereumAddress(str)** | check if the string is an [Ethereum](https://ethereum.org/) address using basic regex. Does not validate address checksums.
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import isUppercase from './lib/isUppercase';
import isIMEI from './lib/isIMEI';

import isAscii from './lib/isAscii';
import isEmoji from './lib/isEmoji';
import isFullWidth from './lib/isFullWidth';
import isHalfWidth from './lib/isHalfWidth';
import isVariableWidth from './lib/isVariableWidth';
Expand Down Expand Up @@ -153,6 +154,7 @@ const validator = {
isLowercase,
isUppercase,
isAscii,
isEmoji,
isFullWidth,
isHalfWidth,
isVariableWidth,
Expand Down
9 changes: 9 additions & 0 deletions src/lib/isEmoji.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import assertString from './util/assertString';

const emojis = /\p{Emoji_Presentation}/u;
const emojiRegex = /[\u{1f300}-\u{1f5ff}\u{1f900}-\u{1f9ff}\u{1f600}-\u{1f64f}\u{1f680}-\u{1f6ff}\u{2600}-\u{26ff}\u{2700}-\u{27bf}\u{1f1e6}-\u{1f1ff}\u{1f191}-\u{1f251}\u{1f004}\u{1f0cf}\u{1f170}-\u{1f171}\u{1f17e}-\u{1f17f}\u{1f18e}\u{3030}\u{2b50}\u{2b55}\u{2934}-\u{2935}\u{2b05}-\u{2b07}\u{2b1b}-\u{2b1c}\u{3297}\u{3299}\u{303d}\u{00a9}\u{00ae}\u{2122}\u{23f3}\u{24c2}\u{23e9}-\u{23ef}\u{25b6}\u{23f8}-\u{23fa}\u{203c}\u{2047}-\u{204A}\u{2195}-\u{2199}]/u;
export default function isEmoji(str) {
assertString(str);

return emojis.test(str) || emojiRegex.test(str);
}
71 changes: 71 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -5738,6 +5738,77 @@ describe('Validators', () => {
});
});

it('should validate a string that contains an emoji', () => {
test({
validator: 'isEmoji',
valid: [
'😋',
'💮',
'🐱',
'horse 🐴',
'🐴🤭',
'lots of emojis !! 😶‍🌫️😺🤖 TEST',
'🧡',
'🔴',
'👌🏻',
'👈',
'☔',
'👎',
'❓',
'®',
'☂',
'🌜',
'🔍',
'🔒',
'⚪',
'⚓',
'✏',
'♦',
'⌛',
'⚡',
'⭐',
'✈',
'☎',
'📷',
'✂',
'⏩',
'✌',
'✌',
'❣',
'♠',
'✔',
'♊',
'⭕',
'©',
'‼',
'⁉',
'❔',
'♾',
'☯',
'➡',
'↕',
'▶',
'☹',
'✝',
'☪',
'✡',
'☸',
'❇',
'❄',
'☺ smile',
'♤',
'❤ heart symbol!',
],
invalid: [
'abc',
'abc123',
'!"#$%&()<>/+=-_? ~^|.,@`{}[]',
'あいうえお',
'你好',
],
});
});

it('should validate full-width strings', () => {
test({
validator: 'isFullWidth',
Expand Down