Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IP address #127

Open
rudashi opened this issue Oct 19, 2019 · 10 comments
Open

IP address #127

rudashi opened this issue Oct 19, 2019 · 10 comments

Comments

@rudashi
Copy link

rudashi commented Oct 19, 2019

How is possible to mask an IP address?

mask: ['###.###.###.###']

This works only if you got full IP, but very common is get ###.###.#.##

@vhoyer
Copy link

vhoyer commented Nov 6, 2019

don't ['###.###.###.###', '###.###.#.##'] work?

@vhoyer
Copy link

vhoyer commented Nov 6, 2019

or maybe you could register another translatrion option, like { 'p': /^(?:1?\d{1,2}|2(?:[0-4]\d|5[0-5]))$/ }, then you register the mask like: 'p.p.p.p'

not that I ever used this lib, just tring to help :D

EDIT:
Just tried, this. Dont work, but the last comment do work :D

We could raise an issue to support patterns that match with more than one character :D

@rudashi
Copy link
Author

rudashi commented Nov 15, 2019

@vhoyer
Thanks for help but your solution with p.p.p.p only works for one digits ip: 1.2.3.4

@vhoyer
Copy link

vhoyer commented Nov 15, 2019

Yeah, sorry, afterwards I went to try it out and figured it doesn't work. I took a look at the code and it would be a pain to implement this :D. I think it is possible, but it would require a lot of work.

That said, my other suggestions (of doing ['###.###.###.###', '###.###.#.##']) does work for your particular problem, I did a small demo here: https://codesandbox.io/s/vue-template-ev453

Is that a super problem?

@rudashi
Copy link
Author

rudashi commented Nov 24, 2019

Unfortunately, it is problematic. I have several extreme cases:

  • ###.###.###.###
  • ###.###.###.##
  • ###.###.###.#
  • ###.###.##.###
  • ###.###.##.##
  • ###.###.##.#
  • ###.###.#.###
  • ###.###.#.##
  • ###.###.#.#

@maiorano84
Copy link

You're also not taking into consideration the fact that "999.999.999.999" would pass the mask validation, but would be an invalid IP address.

You would need a custom token to ensure that you allow 4 groupings of numbers 0-255.

This is untested, but something like this could work:

data() {
    masks: {
        IP: {
            mask: 'B.B.B.B',
            tokens: {
                'B': { pattern: /\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b/ }
            },
        }
    }
},

@vhoyer
Copy link

vhoyer commented Feb 7, 2020

You're also not taking into consideration the fact that "999.999.999.999" would pass the mask validation, but would be an invalid IP address.

You would need a custom token to ensure that you allow 4 groupings of numbers 0-255.

This is untested, but something like this could work:

data() {
    masks: {
        IP: {
            mask: 'B.B.B.B',
            tokens: {
                'B': { pattern: /\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b/ }
            },
        }
    }
},

In fact, I tested this, I mentioned about it on this other comment. Unfortunatly, the custom tokens implementation for a single token match with more than one character does not exist. :/

If you see this while loop closely: https://github.com/vuejs-tips/vue-the-mask/blob/master/src/maskit.js#L7-L26 you will notice that this checks in a per character basis, meaning the custom pattern we made just go through as unmatched :(

Although I think even if we were to open a PR for this feature, no mantainer would bother, as this repo has been staled for like, two and a half years.

@rudashi
Copy link
Author

rudashi commented Feb 7, 2020

Any alternative repo?

@maiorano84
Copy link

@vhoyer Ah, you're right. I completely missed your comment, sorry about that.

And you're 100% right, this library falls short in that it's on a per-character basis. It doesn't look like it was built for this level of pattern-matching.

I've already put in an issue asking for the maintainers to mark this project as abandoned. We'll see if they even bother to respond.

@vhoyer
Copy link

vhoyer commented Feb 7, 2020

There is this guy that posted an issue here about forking this project: #112.

This is the fork: https://github.com/RonaldJerez/vue-the-mask

later on, apparently he decided to create a new package: https://github.com/RonaldJerez/vue-input-facade

Although I haven't tested any of that, the last commit is from January 3rd, so it looks promising

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants