fuxes
fuxes

Reputation: 418

Set invalid input when it has emojis

I'm trying to set an input as invalid if it contains any emoji (aka emoticons) with a directive.

I'm using the following code: http://codepen.io/fuxes/pen/JYJNKW use πŸ»πŸΉπŸŽ‚πŸŽŠπŸŽ‰πŸΈπŸ°πŸ» to start playing.

If I try to use a name such as πŸ»πŸΉπŸŽ‚πŸŽŠπŸŽ‰πŸΈπŸ°πŸ» it works fine, it detects that it has emojis. But the weird thing is that if I start to add any letter, it starts to break!

I'll do the following:
πŸ»πŸΉπŸŽ‚πŸŽŠπŸŽ‰πŸΈπŸ°πŸ»asd -> Emojis where detected
πŸ»πŸΉπŸŽ‚πŸŽŠπŸŽ‰πŸΈπŸ°πŸ»asdds -> Emojis where NOT detected
πŸ»πŸΉπŸŽ‚πŸŽŠπŸŽ‰πŸΈπŸ°πŸ»asdd -> Emojis where detected
πŸ»πŸΉπŸŽ‚πŸŽŠπŸŽ‰πŸΈπŸ°πŸ»asdds -> Emojis where detected

Note that 2 and 4 are equals. I don't understand why this behavior happens. Any thoughts?

Upvotes: 0

Views: 185

Answers (1)

Meir
Meir

Reputation: 14395

if you change:

!hasEmojis.test(value)

to:

!value.match(hasEmojis)

I guess something is wrong with your regex or the way you use it, try to first cut it down to 1 or 2 symbols and figure it out and then see if the test method work, or, use the modification I suggested.

Upvotes: 1

Related Questions