Skip to content

Commit 42668ad

Browse files
author
Tom Hanoldt
committed
push for travis
1 parent bb48d84 commit 42668ad

File tree

3 files changed

+94
-93
lines changed

3 files changed

+94
-93
lines changed

README.md

Lines changed: 92 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# jquery.input.validator [![Build Status](https://travis-ci.org/creative-workflow/jquery.input.validator.svg?branch=master)](https://travis-ci.org/creative-workflow/jquery.input.validator) [![Code Climate](https://codeclimate.com/github/creative-workflow/jquery.input.validator/badges/gpa.svg)](https://codeclimate.com/github/creative-workflow/jquery.input.validator)
22

3-
This module helps to handle independent input validation based on standart html attributes.
3+
This module helps to handle input validation based on standart html attributes.
44

55
This plugin uses [jquery.debug](https://github.com/creative-workflow/jquery.debug) so all tracking information can be easily seen in the javascript console.
66

@@ -9,7 +9,8 @@ This plugin uses [jquery.debug](https://github.com/creative-workflow/jquery.debu
99

1010
bower install jquery.input.validator
1111

12-
# or
12+
# or
13+
1314
npm install jquery.input.validator
1415

1516
```
@@ -43,93 +44,93 @@ It also exposes the class `InputValidator` for manual instantiating.
4344
### Configuration
4445
####
4546
```coffee
46-
validateOnFocusOut: true
47-
validateOnKeyUp: false
48-
validateOnClick: false
49-
50-
focusInvalidElement: true
51-
removeHintOnFocus: false
52-
53-
selectors:
54-
elements: 'input, textarea, select'
55-
ignore: ':hidden'
56-
57-
classes:
58-
error: 'error'
59-
valid: 'valid'
60-
hint: 'error-hint'
61-
62-
pattern:
63-
decimal: /^[\d\.]*$/
64-
number: /^\d*$/
65-
tel: /^[0-9/\-\+\s\(\)]*$/
66-
email: /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
67-
68-
rules:
69-
number: (validator, $element, value) ->
70-
return true if $element.attr('type') != 'number' || !(''+value).length
71-
validator.config.pattern.number.test(value)
72-
73-
tel: (validator, $element, value) ->
74-
return true if $element.attr('type') != 'tel' || !(''+value).length
75-
validator.config.pattern.tel.test(value)
76-
77-
email: (validator, $element, value) ->
78-
return true if $element.attr('type') != 'email' || !(''+value).length
79-
validator.config.pattern.email.test(value)
80-
81-
minlength: (validator, $element, value) ->
82-
return true unless $element.attr('minlength')
83-
('' + value).length >= parseInt($element.attr('minlength'), 10)
84-
85-
maxlength: (validator, $element, value) ->
86-
return true unless $element.attr('maxlength')
87-
('' + value).length <= parseInt($element.attr('maxlength'), 10)
88-
89-
required: (validator, $element, value) ->
90-
return true unless $element.attr('required')
91-
return false if value == undefined || value == null
92-
return !!value.length if typeof(value) in ['string', 'array' ]
93-
!!value
94-
95-
pattern: (validator, $element, value) ->
96-
return true if !$element.attr('pattern') || !(''+value).length
97-
(''+value).match($element.attr('pattern'))
98-
99-
hasClass: (validator, $element, value) ->
100-
return true unless $element.data('rule-has-class')
101-
$element.hasClass($element.data('rule-has-class'))
102-
103-
decimal: (validator, $element, value) ->
104-
return true unless $element.data('rule-decimal') || !(''+value).length
105-
validator.config.pattern.decimal.test(value)
106-
107-
messages:
108-
generic: 'invalid'
109-
email: 'invalid email'
110-
tel: 'invalid phone number'
111-
number: 'invalid number'
112-
minlength: 'to short'
113-
maxlength: 'to long'
114-
required: 'required'
115-
hasClass: 'missing class'
116-
117-
handler:
118-
onValid: null
119-
onInvalid: null
120-
onReset: null
121-
onBuildErrorElement: (validator, $element, value, errors) ->
122-
error = errors[0]
123-
$hint = $element.parent().find(validator.config.classes.hint)
124-
125-
unless $hint.length
126-
$hint = $("<label class='#{validator.config.classes.hint}' " +
127-
"for='#{$element.attr('id')}'>" +
128-
error.message +
129-
"</label>")
130-
131-
$element.data('inputvalidator-hint', $hint)
132-
$element.after($hint)
47+
validateOnFocusOut: true
48+
validateOnKeyUp: false
49+
validateOnClick: false
50+
51+
focusInvalidElement: true
52+
removeHintOnFocus: false
53+
54+
selectors:
55+
elements: 'input, textarea, select'
56+
ignore: ':hidden'
57+
58+
classes:
59+
error: 'error'
60+
valid: 'valid'
61+
hint: 'error-hint'
62+
63+
pattern:
64+
decimal: /^[\d\.]*$/
65+
number: /^\d*$/
66+
tel: /^[0-9/\-\+\s\(\)]*$/
67+
email: /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
68+
69+
rules:
70+
number: (validator, $element, value) ->
71+
return true if $element.attr('type') != 'number' || !(''+value).length
72+
validator.config.pattern.number.test(value)
73+
74+
tel: (validator, $element, value) ->
75+
return true if $element.attr('type') != 'tel' || !(''+value).length
76+
validator.config.pattern.tel.test(value)
77+
78+
email: (validator, $element, value) ->
79+
return true if $element.attr('type') != 'email' || !(''+value).length
80+
validator.config.pattern.email.test(value)
81+
82+
minlength: (validator, $element, value) ->
83+
return true unless $element.attr('minlength')
84+
('' + value).length >= parseInt($element.attr('minlength'), 10)
85+
86+
maxlength: (validator, $element, value) ->
87+
return true unless $element.attr('maxlength')
88+
('' + value).length <= parseInt($element.attr('maxlength'), 10)
89+
90+
required: (validator, $element, value) ->
91+
return true unless $element.attr('required')
92+
return false if value == undefined || value == null
93+
return !!value.length if typeof(value) in ['string', 'array' ]
94+
!!value
95+
96+
pattern: (validator, $element, value) ->
97+
return true if !$element.attr('pattern') || !(''+value).length
98+
(''+value).match($element.attr('pattern'))
99+
100+
hasClass: (validator, $element, value) ->
101+
return true unless $element.data('rule-has-class')
102+
$element.hasClass($element.data('rule-has-class'))
103+
104+
decimal: (validator, $element, value) ->
105+
return true unless $element.data('rule-decimal') || !(''+value).length
106+
validator.config.pattern.decimal.test(value)
107+
108+
messages:
109+
generic: 'invalid'
110+
email: 'invalid email'
111+
tel: 'invalid phone number'
112+
number: 'invalid number'
113+
minlength: 'to short'
114+
maxlength: 'to long'
115+
required: 'required'
116+
hasClass: 'missing class'
117+
118+
handler:
119+
onValid: null
120+
onInvalid: null
121+
onReset: null
122+
onBuildErrorElement: (validator, $element, value, errors) ->
123+
error = errors[0]
124+
$hint = $element.parent().find(validator.config.classes.hint)
125+
126+
unless $hint.length
127+
$hint = $("<label class='#{validator.config.classes.hint}' " +
128+
"for='#{$element.attr('id')}'>" +
129+
error.message +
130+
"</label>")
131+
132+
$element.data('inputvalidator-hint', $hint)
133+
$element.after($hint)
133134

134135
```
135136

@@ -147,10 +148,10 @@ It also exposes the class `InputValidator` for manual instantiating.
147148
#### Setup
148149
* `npm install`
149150
* `bower install`
150-
* `npm test`
151+
* `npm run test`
151152

152153
#### Run tests and linter
153-
* `npm test`
154+
* `npm run test`
154155

155156
#### Generate build
156157
* `npm run build`

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"authors": [
66
"Tom Hanoldt <[email protected]>"
77
],
8-
"description": "This module helps to handle independent input validation based on standart html attributes.",
8+
"description": "This module helps to handle input validation based on standart html attributes.",
99
"main": "src/jquery.input.validator.coffee",
1010
"moduleType": [
1111
"globals"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jquery.input.validator",
33
"version": "1.0.0",
4-
"description": "This module helps to handle independent input validation based on standart html attributes.",
4+
"description": "This module helps to handle input validation based on standart html attributes.",
55
"main": "dist/jquery.input.validator.js",
66
"repository": {
77
"type": "git",

0 commit comments

Comments
 (0)