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

Add support for hexademical only characters #643

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dist/cleave-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ return /******/ (function(modules) { // webpackBootstrap
// strip non-numeric characters
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;

// strip non-hexadecimal characters
value = pps.hexadecimalOnly ? Util.strip(value, /[^0-9a-fA-F]/g) : value;

// convert case
value = pps.uppercase ? value.toUpperCase() : value;
value = pps.lowercase ? value.toLowerCase() : value;
Expand Down Expand Up @@ -1674,9 +1677,11 @@ return /******/ (function(modules) { // webpackBootstrap

// others
target.swapHiddenInput = !!opts.swapHiddenInput;

target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;

target.hexadecimalOnly = target.creditCard || target.date || !!opts.hexadecimalOnly;

target.uppercase = !!opts.uppercase;
target.lowercase = !!opts.lowercase;

Expand Down
4 changes: 2 additions & 2 deletions dist/cleave-angular.min.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion dist/cleave-esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1012,9 +1012,11 @@ var DefaultProperties = {

// others
target.swapHiddenInput = !!opts.swapHiddenInput;

target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;

target.hexadecimalOnly = target.creditCard || target.date || !!opts.hexadecimalOnly;

target.uppercase = !!opts.uppercase;
target.lowercase = !!opts.lowercase;

Expand Down Expand Up @@ -1355,6 +1357,9 @@ Cleave.prototype = {
// strip non-numeric characters
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;

// strip non-hexadecimal characters
value = pps.hexadecimalOnly ? Util.strip(value, /[^0-9a-fA-F]/g) : value;

// convert case
value = pps.uppercase ? value.toUpperCase() : value;
value = pps.lowercase ? value.toLowerCase() : value;
Expand Down
2 changes: 1 addition & 1 deletion dist/cleave-esm.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions dist/cleave-react-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ return /******/ (function(modules) { // webpackBootstrap
// strip non-numeric characters
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;

// strip non-hexadecimal characters
value = pps.hexadecimalOnly ? Util.strip(value, /[^0-9a-fA-F]/g) : value;

// convert case
value = pps.uppercase ? value.toUpperCase() : value;
value = pps.lowercase ? value.toLowerCase() : value;
Expand Down Expand Up @@ -2850,6 +2853,8 @@ return /******/ (function(modules) { // webpackBootstrap

target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;

target.hexadecimalOnly = target.creditCard || target.date || !!opts.hexadecimalOnly;

target.uppercase = !!opts.uppercase;
target.lowercase = !!opts.lowercase;

Expand Down
5 changes: 3 additions & 2 deletions dist/cleave-react-node.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions dist/cleave-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ return /******/ (function(modules) { // webpackBootstrap
// strip non-numeric characters
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;

// strip non-hexadecimal characters
value = pps.hexadecimalOnly ? Util.strip(value, /[^0-9a-fA-F]/g) : value;

// convert case
value = pps.uppercase ? value.toUpperCase() : value;
value = pps.lowercase ? value.toLowerCase() : value;
Expand Down Expand Up @@ -3044,6 +3047,8 @@ return /******/ (function(modules) { // webpackBootstrap

target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;

target.hexadecimalOnly = target.creditCard || target.date || !!opts.hexadecimalOnly;

target.uppercase = !!opts.uppercase;
target.lowercase = !!opts.lowercase;

Expand Down
6 changes: 3 additions & 3 deletions dist/cleave-react.min.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion dist/cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ return /******/ (function(modules) { // webpackBootstrap
// strip non-numeric characters
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;

// strip non-hexadecimal characters
value = pps.hexadecimalOnly ? Util.strip(value, /[^0-9a-fA-F]/g) : value;

// convert case
value = pps.uppercase ? value.toUpperCase() : value;
value = pps.lowercase ? value.toLowerCase() : value;
Expand Down Expand Up @@ -1617,9 +1620,11 @@ return /******/ (function(modules) { // webpackBootstrap

// others
target.swapHiddenInput = !!opts.swapHiddenInput;

target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;

target.hexadecimalOnly = target.creditCard || target.date || !!opts.hexadecimalOnly;

target.uppercase = !!opts.uppercase;
target.lowercase = !!opts.lowercase;

Expand Down
4 changes: 2 additions & 2 deletions dist/cleave.min.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions doc/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- [noImmediatePrefix](#noimmediateprefix)
- [rawValueTrimPrefix](#rawvaluetrimprefix)
- [numericOnly](#numericonly)
- [hexadecimalOnly](#hexadecimalonly)
- [uppercase](#uppercase)
- [lowercase](#lowercase)
- [swapHiddenInput](#swaphiddeninput)
Expand Down Expand Up @@ -554,6 +555,16 @@ Ignored by `creditCard` and `date` shortcuts mode, the value will always be `tru

**Default value**: `false`

### `hexadecimalOnly`

A `Boolean` value indicates if it only allows hexadecimal characters (0-9, a-f, A-F).

Ignored by `creditCard` and `date` shortcuts mode, the value will always be `true`.

`hexadecimalOnly` doesn't work on it's own, you have to either specify the shortcuts mode or `blocks` option to enable the formatter.

**Default value**: `false`

### `uppercase`

A `Boolean` value indicates if it converts value to uppercase letters.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ Cleave.prototype = {
// strip non-numeric characters
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;

// strip non-hexadecimal characters
value = pps.hexadecimalOnly ? Util.strip(value, /[^0-9a-fA-F]/g) : value;

// convert case
value = pps.uppercase ? value.toUpperCase() : value;
value = pps.lowercase ? value.toLowerCase() : value;
Expand Down
3 changes: 3 additions & 0 deletions src/Cleave.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ var cleaveReactClass = CreateReactClass({
// strip non-numeric characters
value = pps.numericOnly ? Util.strip(value, /[^\d]/g) : value;

// strip non-hexadecimal characters
value = pps.hexadecimalOnly ? Util.strip(value, /[^0-9a-fA-F]/g) : value;

// convert case
value = pps.uppercase ? value.toUpperCase() : value;
value = pps.lowercase ? value.toLowerCase() : value;
Expand Down
4 changes: 3 additions & 1 deletion src/common/DefaultProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ var DefaultProperties = {

// others
target.swapHiddenInput = !!opts.swapHiddenInput;

target.numericOnly = target.creditCard || target.date || !!opts.numericOnly;

target.hexadecimalOnly = target.creditCard || target.date || !!opts.hexadecimalOnly;

target.uppercase = !!opts.uppercase;
target.lowercase = !!opts.lowercase;

Expand Down
11 changes: 11 additions & 0 deletions test/browser/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ describe('Custom input field', function () {
assert.equal(field.value, '123 45');
});

it('should use hexadecimal only option', function () {
var cleave = new Cleave(field, {
blocks: [8, 4, 4, 4, 12],
delimiter: '-',
hexadecimalOnly: true,
});

cleave.setRawValue('0z50e8400ze29bz41d4za716x446655440000');
assert.equal(field.value, '050e8400-e29b-41d4-a716-446655440000');
});

it('should use uppercase option', function () {
var cleave = new Cleave(field, {
uppercase: true,
Expand Down