Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 19ec993

Browse files
committed
docs(ngPattern): add note about using the g flag
Add a note to point out that using the `g` flag on the validation RegExp, will cause each search to start at the index of the last search's match, thus not taking the whole input value into account. Closes #11917 Closes #11928
1 parent 213c2a7 commit 19ec993

File tree

1 file changed

+46
-18
lines changed

1 file changed

+46
-18
lines changed

src/ng/directive/input.js

+46-18
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ var inputType = {
4646
* as in the ngPattern directive.
4747
* @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match
4848
* a RegExp found by evaluating the Angular expression given in the attribute value.
49-
* If the expression evaluates to a RegExp object then this is used directly.
50-
* If the expression is a string then it will be converted to a RegExp after wrapping it in `^` and `$`
51-
* characters. For instance, `"abc"` will be converted to `new RegExp('^abc$')`.
49+
* If the expression evaluates to a RegExp object, then this is used directly.
50+
* If the expression evaluates to a string, then it will be converted to a RegExp
51+
* after wrapping it in `^` and `$` characters. For instance, `"abc"` will be converted to
52+
* `new RegExp('^abc$')`.<br />
53+
* **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
54+
* start at the index of the last search's match, thus not taking the whole input value into
55+
* account.
5256
* @param {string=} ngChange Angular expression to be executed when input changes due to user
5357
* interaction with the input element.
5458
* @param {boolean=} [ngTrim=true] If set to false Angular will not automatically trim the input.
@@ -626,9 +630,13 @@ var inputType = {
626630
* as in the ngPattern directive.
627631
* @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match
628632
* a RegExp found by evaluating the Angular expression given in the attribute value.
629-
* If the expression evaluates to a RegExp object then this is used directly.
630-
* If the expression is a string then it will be converted to a RegExp after wrapping it in `^` and `$`
631-
* characters. For instance, `"abc"` will be converted to `new RegExp('^abc$')`.
633+
* If the expression evaluates to a RegExp object, then this is used directly.
634+
* If the expression evaluates to a string, then it will be converted to a RegExp
635+
* after wrapping it in `^` and `$` characters. For instance, `"abc"` will be converted to
636+
* `new RegExp('^abc$')`.<br />
637+
* **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
638+
* start at the index of the last search's match, thus not taking the whole input value into
639+
* account.
632640
* @param {string=} ngChange Angular expression to be executed when input changes due to user
633641
* interaction with the input element.
634642
*
@@ -720,9 +728,13 @@ var inputType = {
720728
* as in the ngPattern directive.
721729
* @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match
722730
* a RegExp found by evaluating the Angular expression given in the attribute value.
723-
* If the expression evaluates to a RegExp object then this is used directly.
724-
* If the expression is a string then it will be converted to a RegExp after wrapping it in `^` and `$`
725-
* characters. For instance, `"abc"` will be converted to `new RegExp('^abc$')`.
731+
* If the expression evaluates to a RegExp object, then this is used directly.
732+
* If the expression evaluates to a string, then it will be converted to a RegExp
733+
* after wrapping it in `^` and `$` characters. For instance, `"abc"` will be converted to
734+
* `new RegExp('^abc$')`.<br />
735+
* **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
736+
* start at the index of the last search's match, thus not taking the whole input value into
737+
* account.
726738
* @param {string=} ngChange Angular expression to be executed when input changes due to user
727739
* interaction with the input element.
728740
*
@@ -815,9 +827,13 @@ var inputType = {
815827
* as in the ngPattern directive.
816828
* @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match
817829
* a RegExp found by evaluating the Angular expression given in the attribute value.
818-
* If the expression evaluates to a RegExp object then this is used directly.
819-
* If the expression is a string then it will be converted to a RegExp after wrapping it in `^` and `$`
820-
* characters. For instance, `"abc"` will be converted to `new RegExp('^abc$')`.
830+
* If the expression evaluates to a RegExp object, then this is used directly.
831+
* If the expression evaluates to a string, then it will be converted to a RegExp
832+
* after wrapping it in `^` and `$` characters. For instance, `"abc"` will be converted to
833+
* `new RegExp('^abc$')`.<br />
834+
* **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
835+
* start at the index of the last search's match, thus not taking the whole input value into
836+
* account.
821837
* @param {string=} ngChange Angular expression to be executed when input changes due to user
822838
* interaction with the input element.
823839
*
@@ -1439,9 +1455,15 @@ function checkboxInputType(scope, element, attr, ctrl, $sniffer, $browser, $filt
14391455
* @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than
14401456
* maxlength. Setting the attribute to a negative or non-numeric value, allows view values of any
14411457
* length.
1442-
* @param {string=} ngPattern Sets `pattern` validation error key if the value does not match the
1443-
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
1444-
* patterns defined as scope expressions.
1458+
* @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match
1459+
* a RegExp found by evaluating the Angular expression given in the attribute value.
1460+
* If the expression evaluates to a RegExp object, then this is used directly.
1461+
* If the expression evaluates to a string, then it will be converted to a RegExp
1462+
* after wrapping it in `^` and `$` characters. For instance, `"abc"` will be converted to
1463+
* `new RegExp('^abc$')`.<br />
1464+
* **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
1465+
* start at the index of the last search's match, thus not taking the whole input value into
1466+
* account.
14451467
* @param {string=} ngChange Angular expression to be executed when input changes due to user
14461468
* interaction with the input element.
14471469
* @param {boolean=} [ngTrim=true] If set to false Angular will not automatically trim the input.
@@ -1472,9 +1494,15 @@ function checkboxInputType(scope, element, attr, ctrl, $sniffer, $browser, $filt
14721494
* @param {number=} ngMaxlength Sets `maxlength` validation error key if the value is longer than
14731495
* maxlength. Setting the attribute to a negative or non-numeric value, allows view values of any
14741496
* length.
1475-
* @param {string=} ngPattern Sets `pattern` validation error key if the value does not match the
1476-
* RegExp pattern expression. Expected value is `/regexp/` for inline patterns or `regexp` for
1477-
* patterns defined as scope expressions.
1497+
* @param {string=} ngPattern Sets `pattern` validation error key if the ngModel value does not match
1498+
* a RegExp found by evaluating the Angular expression given in the attribute value.
1499+
* If the expression evaluates to a RegExp object, then this is used directly.
1500+
* If the expression evaluates to a string, then it will be converted to a RegExp
1501+
* after wrapping it in `^` and `$` characters. For instance, `"abc"` will be converted to
1502+
* `new RegExp('^abc$')`.<br />
1503+
* **Note:** Avoid using the `g` flag on the RegExp, as it will cause each successive search to
1504+
* start at the index of the last search's match, thus not taking the whole input value into
1505+
* account.
14781506
* @param {string=} ngChange Angular expression to be executed when input changes due to user
14791507
* interaction with the input element.
14801508
* @param {boolean=} [ngTrim=true] If set to false Angular will not automatically trim the input.

0 commit comments

Comments
 (0)