Skip to content

Commit

Permalink
Added zip code types
Browse files Browse the repository at this point in the history
  • Loading branch information
kloverde committed Jan 4, 2017
1 parent e08cc0a commit 93585e2
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 12 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Release 1.3 (January 3, 2017)

* Added zip code types


# Release 1.2 (December 28, 2016)

* Now confirmed to work on mobile! See README.md for a list of tested browsers.
* Change to event firing: validation success & validation failure events were firing pre-blur with `preventInvalidInput` enabled. This is contrary to the documentation, which states that these events do not fire in that scenario. The documentation reflected the intended behavior; the events no longer fire in this scenario.
* Added credit cards types (AMEX, VISA, MasterCard, Discover), plus a credit card type encompassing each of these types
* Added credit card types (AMEX, VISA, MasterCard, Discover), plus a credit card type encompassing each of these types
* Added a [Luhn](https://en.wikipedia.org/wiki/Luhn_algorithm) type
* Updated and redesigned the demo page
* The unit tests are no longer implemented with Java/Selenium/JUnit; they've been re-implemented in JavaScript/QUnit. This dramatically improves test performance and greatly simplifies running tests (just open the HTML file).
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
RestrictedTextField v1.2
RestrictedTextField v1.3
========================

See LICENSE for this software's licensing terms.

RestrictedTextField is a jQuery plugin which uses regular expressions to validate and control input to HTML text fields. Using 35 built-in types or types you define yourself, it allows you to suppress invalid keystrokes or to allow them into the field for later validation. Fields are always validated on blur.
RestrictedTextField is a jQuery plugin which uses regular expressions to validate and control input to HTML text fields. Using 38 built-in types or types you define yourself, it allows you to suppress invalid keystrokes or to allow them into the field but be flagged incorrect. Validation is performed on keystroke, paste and blur.


## Features

* Discard invalid keystrokes or catch a validation failure event to handle it as you wish
* Has 35 built-in types
* Has 38 built-in types
* Extensible: define your own types
* Money types automatically format on blur to end in a decimal point and two digits

Expand Down Expand Up @@ -51,6 +51,9 @@ RestrictedTextField is a jQuery plugin which uses regular expressions to validat
33. Discover
34. Credit Card (combines all of the individual credit card types above)
35. [Luhn-valid](https://en.wikipedia.org/wiki/Luhn_algorithm) numbers
36. US zip code (5 digits)
37. US zip code suffix (1-4 digits)
38. US zip code (5 digits with optional suffix)


## What's the difference between integer/strict integer, float/strict float?
Expand Down Expand Up @@ -87,7 +90,7 @@ If you prefer not to use strictly-enforced credit card types (is Wikipedia corre

| Property | Description | Data Type | Valid Values | Default Value |
| -------- | --------------|---------- |----------------------|---------------|
| `type` | Text field type. This is a required setting. | string | alpha, upperAlpha, lowerAlpha, alphaSpace, upperAlphaSpace, lowerAlphaSpace, alphanumeric, upperAlphanumeric, lowerAlphanumeric, alphanumericSpace, upperAlphanumericSpace, lowerAlphanumericSpace, int, positiveInt, negativeInt, strictInt, strictPositiveInt, strictNegativeInt, float, positiveFloat, negativeFloat, strictFloat, strictPositiveFloat, strictNegativeFloat, money, positiveMoney, negativeMoney, accountingMoney, negativeAccountingMoney, americanExpress, visa, masterCard, discover, creditCard, luhnNumber | null |
| `type` | Text field type. This is a required setting. | string | alpha, upperAlpha, lowerAlpha, alphaSpace, upperAlphaSpace, lowerAlphaSpace, alphanumeric, upperAlphanumeric, lowerAlphanumeric, alphanumericSpace, upperAlphanumericSpace, lowerAlphanumericSpace, int, positiveInt, negativeInt, strictInt, strictPositiveInt, strictNegativeInt, float, positiveFloat, negativeFloat, strictFloat, strictPositiveFloat, strictNegativeFloat, money, positiveMoney, negativeMoney, accountingMoney, negativeAccountingMoney, americanExpress, visa, masterCard, discover, creditCard, luhnNumber, usZip, usZip5, usZipSuffix | null |
| `preventInvalidInput` | When enabled, invalid keystrokes are ignored (the value of the text field is not updated). When disabled, invalid keystrokes are not ignored. | boolean | true/false | true |
| `logger` | An optional callback function for logging. If you want to enable logging, provide a function and then do whatever you wish with the message. | function | A function accepting the log message as a string argument | undefined |

Expand Down
2 changes: 2 additions & 0 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
"} );<br/>\n" +
"</code>\n"
);

field.focus();
}

function flashBorder( jqField, cssClass, times, delayMillis ) {
Expand Down
8 changes: 6 additions & 2 deletions src/jquery.restrictedtextfield.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* RestrictedTextField v1.2
* RestrictedTextField v1.3
* https://www.github.com/kloverde/jquery-RestrictedTextField
*
* Copyright (c) 2016, Kurtis LoVerde
Expand Down Expand Up @@ -208,6 +208,10 @@
// leave it to your payment card processor to reject an invalid credit card number, while still using Luhn validation to
// reject a number that has no possibility of being valid. This is the safest option, but the choice is yours.
_addType( dest, "luhnNumber", /^\d+$/ , null );

_addType( dest, "usZip", /^\d{5}(\-\d{1,4})?$/ , /^(\d{1,5}|\d{5}\-|\d{5}\-\d{1,4})$/ );
_addType( dest, "usZip5", /^\d{5}$/ , /^\d{1,5}$/ );
_addType( dest, "usZipSuffix", /^\d{1,4}$/ , null );
}

var regexes = $.fn.restrictedTextField.types[ settings.type ];
Expand Down Expand Up @@ -391,7 +395,7 @@
}

if( (integerPart === "" || parseInt(integerPart) === 0) && (parseInt(decimalPart) === 0) ) {
formatted = "0.00"
formatted = "0.00";
} else {
formatted = openParen
+ sign
Expand Down
4 changes: 2 additions & 2 deletions src/jquery.restrictedtextfield.min.js

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

Loading

0 comments on commit 93585e2

Please sign in to comment.