Reputation: 418
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
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