normalizer( value )Returns: String
Description: Prepares/transforms the elements value for validation.
-
normalizer( value )
-
valueType: StringThe value of the element.
-
Transform the value of an element and the result for validation instead of the initial value. The normalizer can be defined global to all elements or local to only one element. With that said, the local normalizer will only run for the element for which it was defined. The global normalizer will run for all validated elements. This normalizer can be then overrided for each element, as needed, by attaching one to it. This way only the local one will run for that element, and the global one will run for others.
Note that this method:
-
Has been available since version
1.15.0
-
Doesn't change the elements' value, it only changes the value used for validation.
-
Gets the value passed as argument, and "this" within it references the corresponding
DOMElement
. -
For versions between
1.15.0
and1.17.0
, it must return a string value. And as of1.17.1
, it can return any value includingnull
andundefined
.
Examples:
Example: Makes "field" required and use a normalizer to trim its value before validating
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
|
Demo:
Example: Makes "url" required and use a normalizer to append 'http://', if not present, to the value of the "url" element before validating
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
|
Demo:
Example: Using a global normalizer in conjunction with a local one
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
|