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

allow hexadecimal masks #30

Closed
hoeni opened this issue Jun 28, 2013 · 7 comments
Closed

allow hexadecimal masks #30

hoeni opened this issue Jun 28, 2013 · 7 comments

Comments

@hoeni
Copy link

hoeni commented Jun 28, 2013

It would be great to have a placeholder for hexadecimal input, enabling input for mac addresses for example:

FF:FF:FF:FF:FF:FF

It would be helpful to normalize this to either caps (F) or normal letters (f), depending on the placeholder.

@igorescobar
Copy link
Owner

You can do it:
$('.date').mask('FF:FF:FF:FF:FF:FF', {translation: {"F":"[0-9a-z]"}});

@hoeni
Copy link
Author

hoeni commented Jun 28, 2013

Hi Igor,

Thanks for your quick reply!

That's what I'm doing at the moment and normalizing the input on the server side afterwards. It would be a great enhancement for the user experience though, if the input of the user is normalized while he types:

Say, I want to see capital letters for my hex, and the user types 0a:0F, it should be normalized to "0A:0F" (or "0a:0f", if I want to see small caps)

Asides from using two special mask characters like f and F there could be at least a generic alternative like having an additional option e.g.

$('.date').mask('FF:FF:FF:FF:FF:FF', {
    translation: {"F":"[0-9a-z]"},
    conversion: {"ABCDEF" => "abcdef"}
});

or similar configuration.

Tobi

@igorescobar
Copy link
Owner

Hi @hoeni
Assuming that is an specific use case, I don't see why I should implement that kind of implementation on a "generic" manner, that would increase the plugin's source code on a very significant way and the value in return would be very small. Although, you can implement this behaviour for your users using callbacks that jquery mask offers.

Example:

$('.date').mask('AA:AA:AA:AA:AA:AA', {
        onKeyPress: function(str, e, obj){ 
            $(obj).val(str.toLowerCase());
        }
   }
);

Hope it helps.

@hoeni
Copy link
Author

hoeni commented Jul 1, 2013

Hi,

that works like a charm! I wasn't aware of the keypress callback!
Thank you so much!

Tobi

@igorescobar
Copy link
Owner

No problem! Enjoy ;)

@brunowego
Copy link

My solution for hex color:

$('.hexcolor').mask('SAAAAAA', {
    'translation': {
        S: {
            pattern: /[#]/
        },
        A: {
            pattern: /[A-Fa-f0-9]/
        }
    }
});

@igorescobar
Copy link
Owner

👍

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