RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.37k stars 2.17k forks source link

Timezone mask #2730

Closed mtorak closed 9 months ago

mtorak commented 11 months ago

Trying to create a timezone mask which accepts below texts, but it's impossible to input many of them. Implementation details are in the jsfiddle. BTW, regex used for this inputmask matches all of below texts on https://regex101.com

Input texts: GMT UTC -1200 +03 +04:00 GMT-03 GMT+09:00 GMT+02 UTC-08 UTC-05:30 UTC+11 CET PST CDT

Regex: (((GMT|UTC)([+-])(?:1[0-4]|0[0-9])(?::?[0-5][0-9])?)|(GMT|UTC|CET|CEST|EST|EDT|CST|CDT|MST|MDT|PST|PDT)|(([+-])(?:1[0-4]|0[0-9])(?::?[0-5][0-9])?))

Thank you

RobinHerbots commented 10 months ago

Hi @mtorak ,

I examined you mask and seprated the regex in 3 seperate part to see where it went wrong.
Something like:

    Inputmask({
        // regex: "((GMT|UTC)([+-])(?:1[0-4]|0[0-9])(?::?[0-5][0-9])?)",
        // regex: "(GMT|UTC|CET|CEST|EST|EDT|CST|CDT|MST|MDT|PST|PDT)",
        // regex: "(([+-])(?:1[0-4]|0[0-9])(?::?[0-5][0-9])?)"
        regex: "(((GMT|UTC)([+-])(?:1[0-4]|0[0-9])(?::?[0-5][0-9])?)|(GMT|UTC|CET|CEST|EST|EDT|CST|CDT|MST|MDT|PST|PDT)|(([+-])(?:1[0-4]|0[0-9])(?::?[0-5][0-9])?))",
    }).mask("#test1");

Anyway the issue was due to the 2nd part and the keepStatic which is not set.

adding keepStatic: false option will solve the issue.

    Inputmask({
        regex: "(((GMT|UTC)([+-])(?:1[0-4]|0[0-9])(?::?[0-5][0-9])?)|(GMT|UTC|CET|CEST|EST|EDT|CST|CDT|MST|MDT|PST|PDT)|(([+-])(?:1[0-4]|0[0-9])(?::?[0-5][0-9])?))",
                keepStatic: false
    }).mask("#test1");

https://robinherbots.github.io/Inputmask/#/documentation#keepstatic

mtorak commented 10 months ago

Thank you @RobinHerbots, It's almost working as expected, only glitch is below UTC inputs are not allowed, but these values are also valid. UTC UTC-08 UTC-05:30 UTC+11

Here is updated jsfiddle: https://jsfiddle.net/p2oszncr/

Thanks in advance.

RobinHerbots commented 10 months ago

@mtorak ,

I have updated the inputmask version to the latest in youtr fiddle. Indeed. I can enter U, but then it stops. (btw I added the casing option, so you can just type in lowercase)

I will have a deeper look and come back to you.

mtorak commented 10 months ago

Ok thank you, have saved your changes, can you share your changed version link?

"Indeed. I can enter U, but then it stops." Yes that's the case, waiting for your further examination.

BR

RobinHerbots commented 9 months ago

Can you have a try with thé latest version 5.0.9 beta 33

RobinHerbots commented 9 months ago

Here is an updated jsfiddle https://jsfiddle.net/dLsfvy04/

mtorak commented 9 months ago

I've tried your beta version, it works as expected. But there is a big issue, after trying it with 15-20 inputs, it freezes browser! The very same browser freezing issue also exists in your jsfiddle, just try it 15-20 times with different inputs you will see it's freezing browser.

The error code is the same as below one. https://stackoverflow.com/questions/67519860/chrome-passes-error-code-sigill-when-running-javascript

Could there be an infinite blocking loop etc in your code?

RobinHerbots commented 9 months ago

https://jsfiddle.net/g2dvu80L/

How exactly do you reproduce the error? Which OS & Browser & versions.

mtorak commented 9 months ago

Just tried with several inputs for 3-4 minutes. Now I couldn't re-produce it, OS is linux, browser: chrome Version 117.0.5938.11

mtorak commented 9 months ago

One of my colleagues also stumbled upon once that case. He couldn't reproduce it. I think it was related to browser, we are still testing it, so far no more issues.

Thank you for your effort, this plugin is really useful. Cheers.