Tagify: Strange Behavior when using pattern attribute

Created on 19 Sep 2020  Â·  2Comments  Â·  Source: yairEO/tagify

Prerequisites

  • [X] I am running the latest version
  • [x] I checked the documentation and found no answer
  • [X] I checked to make sure that this issue has not already been filed

Demo Page


https://jsbin.com/rulapikaya/1/edit?html,js,output

Explanation

  • What is the expected behavior?
    I created a regex pattern to match letters and numbers. It should accept strings that are any combination of lowercase or uppercase letters, numbers, and spaces.

  • What is happening instead?
    It accepts strings that are just letters and spaces correctly. However, if there is a number in the string, it will invalidate the tag initially. But if you input the string again, it will accept the string. So if you input "Thing 1" it will invalidate it and remove the tag. But inputting "Thing 1" again will work properly. This happens anytime there's a number in the string.

  • What error message are you getting?
    N/A

Note: I got around this on my personal project by modifying the pattern from

/^[a-zA-Z0-9]+$/g to/^[a-zA-Z][a-zA-Z0-9]+$/g

It works for my purposes but these are two different regex patterns

UPDATE: I'm having the same problem with //^[a-zA-Z][a-zA-Z0-9]{0,19}$/g

Help wanted

All 2 comments

Looking into it, thanks

You do not need the trailing g in your regex.

/^[a-zA-Z0-9 ]+$/g → /^[a-zA-Z0-9 ]+$/

Was this page helpful?
0 / 5 - 0 ratings