You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@
11
11
# Release 1.2 (December 28, 2016)
12
12
13
13
* Now confirmed to work on mobile! See README.md for a list of tested browsers.
14
-
* 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.
14
+
* Change to event firing: validation success & validation failure events were firing pre-blur with `preventInvalidInput` enabled. This was contrary to the documentation, which stated that these events do not fire in that scenario. The documentation reflected the intended behavior; the events no longer fire in this scenario.
15
15
* Added credit card types (AMEX, VISA, MasterCard, Discover), plus a credit card type encompassing each of these types
16
16
* Added a [Luhn](https://en.wikipedia.org/wiki/Luhn_algorithm) type
Copy file name to clipboardExpand all lines: README.md
+11-7Lines changed: 11 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,15 @@
1
1
RestrictedTextField v1.4 (UPCOMING RELEASE)
2
2
========================
3
3
4
-
# You've stumbled upon a development branch. Have a look around if you want, but only use code that's posted on the releases page.
5
-
6
4
See LICENSE for this software's licensing terms.
7
5
8
-
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.
6
+
RestrictedTextField is a jQuery plugin which uses regular expressions to validate and control input to HTML text fields. RestrictedTextField has 38 built-in types and also allows you to define your own types. Validation is performed on keystroke, paste and blur.
7
+
8
+
You might not need this plugin for your purposes - the HTML5 `pattern` attribute provides most of the same functionality. If, however, you must support browsers that don't support `pattern`, or if you want to make use of RestrictedTextField's additional features, then perhaps it might be a good fit for you.
9
+
10
+
The biggest difference between this plugin and `pattern` is that RestrcitedTextField allows you to (optionally) suppress invalid keystrokes in real time, rather than allow them into the field to fail validation later. If you do want to allow invalid characters in, however, you have that option.
11
+
12
+
If you're only interested in `pattern`-based validation, you might still find RestrictedTextField useful. It provides the ability to disable its own validation implementation and use `pattern` exclusively. In this scenario, you'd just be using RestrictedTextField as a repository of pre-written regular expressions. Although you could just copy the regular expressions from the source code, you might find it easier on code maintenance to not be dropping multiple copies of the same regular expressions into your project.
9
13
10
14
11
15
## Features
@@ -53,7 +57,7 @@ RestrictedTextField is a jQuery plugin which uses regular expressions to validat
53
57
32. MasterCard
54
58
33. Discover
55
59
34. Credit Card (combines all of the individual credit card types above)
35.[Luhn](https://en.wikipedia.org/wiki/Luhn_algorithm) numbers - note: if used with `pattern` mode enabled, successful validation is essentially meaningless.
57
61
36. US zip code (5 digits)
58
62
37. US zip code suffix (1-4 digits)
59
63
38. US zip code (5 digits with optional suffix)
@@ -86,7 +90,7 @@ RestrictedTextField is a jQuery plugin which uses regular expressions to validat
86
90
87
91
Each credit card type enforces prefixes and length as specified by https://en.wikipedia.org/wiki/Payment_card_number in December, 2016. [Luhn validation](https://en.wikipedia.org/wiki/Luhn_algorithm) is also performed.
88
92
89
-
If you prefer not to use strictly-enforced credit card types (is Wikipedia correct, and is RestrictedTextField up-to-date?), you can use the Luhn type instead. It performs basic mathematical validation, but it can only tell you that a value is invalid, not that a value IS valid. Full validation would then be shifted to your payment card processor in the form of a rejected transaction -- or, if they provide an API for validation, you could use that.
93
+
If you prefer not to use strictly-enforced credit card types (is Wikipedia correct, and is RestrictedTextField up-to-date?), you can use the Luhn type instead. It performs basic mathematical validation, but that will only tell you that a credit card number is invalid, not that it IS valid. Full validation would then be shifted to your payment card processor in the form of a rejected transaction -- or, if they provide an API for validation, you could use that, too.
90
94
91
95
92
96
## Configuration
@@ -96,12 +100,12 @@ If you prefer not to use strictly-enforced credit card types (is Wikipedia corre
|`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 |
98
102
|`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 |
99
-
|`usePatternAttr`| When enabled, sets the HTML5 `pattern` attribute on the input field. Check [caniuse.com](http://caniuse.com/#search=pattern) for browser support. | boolean | true/false | false |
103
+
|`usePatternAttr`| When enabled, sets the HTML5 `pattern` attribute on the input field. Check [caniuse.com](http://caniuse.com/#search=pattern) for browser support. When pattern mode is enabled, RestrictedTextField does not fire its own validation events, nor does it perform Luhn validation on credit card types or the Luhn type. Pattern mode is meant to be pure HTML5 behavior. The only part of RestrictedTextField functionality that remains active is the automatic formatting of money types.| boolean | true/false | false |
100
104
101
105
102
106
## Events
103
107
104
-
These events are fired based on the state of the text field.
108
+
These events are fired based on the state of the text field, but only if `usePatternAttr` is disabled.
Copy file name to clipboardExpand all lines: demo/demo.html
+2-9Lines changed: 2 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -53,16 +53,9 @@ <h1>Test Drive</h1>
53
53
<divid="instructions">
54
54
<p>Here you can test drive RestrictedTextField's built-in types. Select a type from the dropdown menu and use the checkboxes to further customize the configuration.</p>
55
55
56
-
<p>Regardless of the state of the "Discard invalid keystrokes" checkbox, validation is always performed on each keystroke and on blur.</p>
56
+
<p>If the <ahref="http://caniuse.com/#search=pattern" target="_blank">pattern</a> attribute is disabled, RestrictedTextField uses its own validation implementation: validation is performed on each keystroke and on blur, and is done regardless of the state of the "Discard invalid keystrokes" checkbox. Event listeners flash the text field's border when a keystroke is discarded, and colors its border solid orange if an invalid character makes it into the field.</p>
57
57
58
-
<p>This demo declares event listeners that flash the text field's border when a keystroke is discarded, and colors its border solid red if an invalid character is allowed into the field.</p>
59
-
60
-
<p>
61
-
To better demonstrate the support of the <ahref="http://caniuse.com/#search=pattern" target="_blank">pattern</a> attribute, the event listener which watches for invalid text
62
-
inside the field will be disabled when the pattern attribute is in use. You'll notice that with the pattern attribute, the browser's built-in behavior alters the field's border
63
-
color, but only on blur. Notice how this differs from RestrictedTextField's approach when the pattern attribute isn't turned on. Note: for types which require validation beyond
64
-
a regular expression (for example, a credit card number), the pattern attribute won't provide complete validation; you'll want to heed RestrictedTextField's validation events.
65
-
</p>
58
+
<p>Note that if using the pattern attribute, you will lose Luhn validation on credit card types and the Luhn type, as Luhn calculations cannot be performed with regular expressions. Patten mode is meant to be a pure HTML5 validation.</p>
66
59
67
60
<p>The demo initializes RestrictedTextField with a logging function, so you can open your browser's console to view events in real time.</p>
0 commit comments