Skip to content

Commit 93585e2

Browse files
committed
Added zip code types
1 parent e08cc0a commit 93585e2

File tree

8 files changed

+83
-12
lines changed

8 files changed

+83
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
# Release 1.3 (January 3, 2017)
2+
3+
* Added zip code types
4+
5+
16
# Release 1.2 (December 28, 2016)
27

38
* Now confirmed to work on mobile! See README.md for a list of tested browsers.
49
* 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.
5-
* Added credit cards types (AMEX, VISA, MasterCard, Discover), plus a credit card type encompassing each of these types
10+
* Added credit card types (AMEX, VISA, MasterCard, Discover), plus a credit card type encompassing each of these types
611
* Added a [Luhn](https://en.wikipedia.org/wiki/Luhn_algorithm) type
712
* Updated and redesigned the demo page
813
* 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).

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
RestrictedTextField v1.2
1+
RestrictedTextField v1.3
22
========================
33

44
See LICENSE for this software's licensing terms.
55

6-
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.
6+
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.
77

88

99
## Features
1010

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

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

5558

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

8891
| Property | Description | Data Type | Valid Values | Default Value |
8992
| -------- | --------------|---------- |----------------------|---------------|
90-
| `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 |
93+
| `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 |
9194
| `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 |
9295
| `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 |
9396

demo/demo.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
"} );<br/>\n" +
8787
"</code>\n"
8888
);
89+
90+
field.focus();
8991
}
9092

9193
function flashBorder( jqField, cssClass, times, delayMillis ) {

src/jquery.restrictedtextfield.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* RestrictedTextField v1.2
2+
* RestrictedTextField v1.3
33
* https://www.github.com/kloverde/jquery-RestrictedTextField
44
*
55
* Copyright (c) 2016, Kurtis LoVerde
@@ -208,6 +208,10 @@
208208
// leave it to your payment card processor to reject an invalid credit card number, while still using Luhn validation to
209209
// reject a number that has no possibility of being valid. This is the safest option, but the choice is yours.
210210
_addType( dest, "luhnNumber", /^\d+$/ , null );
211+
212+
_addType( dest, "usZip", /^\d{5}(\-\d{1,4})?$/ , /^(\d{1,5}|\d{5}\-|\d{5}\-\d{1,4})$/ );
213+
_addType( dest, "usZip5", /^\d{5}$/ , /^\d{1,5}$/ );
214+
_addType( dest, "usZipSuffix", /^\d{1,4}$/ , null );
211215
}
212216

213217
var regexes = $.fn.restrictedTextField.types[ settings.type ];
@@ -391,7 +395,7 @@
391395
}
392396

393397
if( (integerPart === "" || parseInt(integerPart) === 0) && (parseInt(decimalPart) === 0) ) {
394-
formatted = "0.00"
398+
formatted = "0.00";
395399
} else {
396400
formatted = openParen
397401
+ sign

src/jquery.restrictedtextfield.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)