diff --git a/.gitignore b/.gitignore index 86aaedee1..740bc11bc 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ yarn.lock /index.js validator.js validator.min.js - +.idea diff --git a/src/index.js b/src/index.js index 87be7113c..4f237771d 100644 --- a/src/index.js +++ b/src/index.js @@ -129,6 +129,7 @@ import isLicensePlate from './lib/isLicensePlate'; import isStrongPassword from './lib/isStrongPassword'; import isVAT from './lib/isVAT'; +import isEmoji from './lib/isEmoji'; const version = '13.15.15'; @@ -245,6 +246,7 @@ const validator = { isLicensePlate, isVAT, ibanLocales, + isEmoji, }; export default validator; diff --git a/src/lib/isEmoji.js b/src/lib/isEmoji.js new file mode 100644 index 000000000..766bfa494 --- /dev/null +++ b/src/lib/isEmoji.js @@ -0,0 +1,8 @@ +import assertString from './util/assertString'; + +const emojiRegex = /(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/; + +export default function isEmoji(str) { + assertString(str); + return emojiRegex.test(str); +} diff --git a/test/validators.test.js b/test/validators.test.js index 299af27d8..51aad8347 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -15652,4 +15652,19 @@ describe('Validators', () => { ], }); }); + it('should validate emojis', () => { + test({ + validator: 'isEmoji', + valid: [ + '🎉', + '❤️', + '🍔', + ], + invalid: [ + 'abc', + '123', + '#000000', + ], + }); + }); });