diff --git a/Gruntfile.js b/Gruntfile.js index a5536ea..1eef85c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -95,13 +95,13 @@ function initializeGruntConfig(grunt) { } }, - // watch for changes to source - // Better than calling grunt a million times - // (call 'grunt watch') watch: { files: [SRC_DIR + '/**'], tasks: ['test'], - options: { nospawn: true} + options: { + nospawn: true, + livereload: true + } }, // Unit tests @@ -114,8 +114,7 @@ function initializeGruntConfig(grunt) { server: { options: { port: 8000, - base: '.', - keepalive: true + base: '.' } } }, @@ -202,7 +201,8 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-umd'); grunt.registerTask("build-production", ["version", "test", "uglify"]); - grunt.registerTask('test', ['concat', 'copy', 'umd', 'cssmin','jshint', 'qunit']); - grunt.registerTask("default", ["test", "watch"]); + grunt.registerTask('build', ['concat', 'copy', 'umd', 'cssmin']); + grunt.registerTask('test', ['build','jshint', 'qunit']); + grunt.registerTask("default", ["test", "connect", "watch"]); grunt.registerTask("prepublish", ["test", "uglify"]); }; diff --git a/README.md b/README.md index ba2ead0..e1e957b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ -# jQuery Form Validator +# jQuery Form Validator [DISCONTINUED] -jQuery Form Validator is a **feature rich and multilingual** jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code. Even though this plugin has a wide range of validation functions it's **designed to require as little network traffic as possible**. This is achieved by grouping together validation functions in "modules", making it possible to load only those functions that's needed to validate a particular form. +*Validation framework that let's you configure, rather than code, your validation logic.* -**Form demos and full documentation available at http://formvalidator.net/** +I started writing this plugin back in 2009 and it has given me much joy over the years. But all good things must come to an end and now it's time for this plugin to pull in its oars and go down with history. -[](https://travis-ci.org/victorjonsson/jQuery-Form-Validator/builds/) +**This plugin is no longer being developed!** It supports jQuery v. 1.8 >= 2.2.4. No pull requests will become merged in but feel free to fork and do whatever you like! + +[](https://travis-ci.org/victorjonsson/jQuery-Form-Validator/builds/) [](https://www.npmjs.com/package/jquery-form-validator) @@ -39,7 +41,7 @@ jQuery Form Validator is a **feature rich and multilingual** jQuery plugin that ### Support for HTML5 -This plugin can serve as a fallback solution for the validation attributes in the HTML5 spec. With the [html5](http://www.formvalidator.net/#configuration_html5) module you can use the following native features: +This plugin can serve as a fallback solution for the validation attributes in the HTML5 spec. With the html5 module you can use the following native features: **Attributes**: require, pattern, maxlength, min, max, placeholder @@ -68,7 +70,7 @@ This plugin can serve as a fallback solution for the validation attributes in th * Create input suggestions with ease, no jquery-ui needed * to apply multiple validators to an input element, separate the validator names using a space (ex: required email) -Read the documentation for the default features at [http://formvalidator.net/#default-validators](http://formvalidator.net/#default-validators) +Read the documentation for the default features at [#default-validators](#default-validators) ### Module: security * **spamcheck** @@ -78,15 +80,15 @@ Read the documentation for the default features at [http://formvalidator.net/#de * **strength** — *Validate the strength of a password* * **server** — *Validate value of input on server side* * **letternumeric** — *Validate that the input value consists out of only letters and/or numbers* - * **recaptcha** - *Validate Google [reCaptcha 2](https://www.google.com/recaptcha/intro/index.html)* + * **recaptcha** - *Validate Google [reCaptcha 2](https://www.google.com/recaptcha/intro/index.html)* -Read the documentation for the security module at [http://formvalidator.net/#security-validators](http://formvalidator.net/#security-validators) +Read the documentation for the security module at [#security-validators](#security-validators) ### Module: date * **time** — *hh:mm* * **birthdate** — *yyyy-mm-dd, not allowing dates in the future or dates that's older than 122 years (format can be customized, more information below)* -Read the documentation for the date module at [http://formvalidator.net/#date-validators](http://formvalidator.net/#date-validators) +Read the documentation for the date module at [#date-validators](#date-validators) ### Module: location * **country** @@ -95,7 +97,7 @@ Read the documentation for the date module at [http://formvalidator.net/#date-va * Suggest countries (english only) * Suggest states in the US -Read the documentation for the location module at [http://formvalidator.net/#location-validators](http://formvalidator.net/#location-validators) +Read the documentation for the location module at [#location-validators](/#location-validators) ### Module: file * **mime** @@ -103,14 +105,14 @@ Read the documentation for the location module at [http://formvalidator.net/#loc * **size** (file size) * **dimension** (size dimension and ratio) -Read the documentation for the file module at [http://formvalidator.net/#file-validators](http://formvalidator.net/#file-validators) +Read the documentation for the file module at [#file-validators](#file-validators) ### Module: logic * **Dependent validation** * **Require "one-of"** -Read the documentation for this module at [http://formvalidator.net/#logic](http://www.formvalidator.net/#logic) +Read the documentation for this module at [/#logic](#logic) ### Module: sepa @@ -133,8 +135,8 @@ Read the documentation for the Swedish module at [http://formvalidator.net/#swed ### Module: uk * **ukvatnumber** - * **uknin** - * **ukutr** + * **uknin** + * **ukutr** Read the documentation for the UK module at [http://formvalidator.net/#uk-validators](http://www.formvalidator.net/#country-specific-validators_uk) @@ -143,11 +145,18 @@ Read the documentation for the UK module at [http://formvalidator.net/#uk-valida * **cep** * **cpf** -### Module: poland +### Module: poland * **plpesel** - *validate polish personal identity number (in Polish identity cards)* * **plnip** - *validate polish VAT identification number* * **plregon** - *validate polish bussiness identity number* +### Module: color + * **hex** - *validate hex color format* + * **rgb** - *validate rgb color format* + * **rgba** - *validate rgba color format* + * **hsl** - *validate hsl color format* + * **hsla** - *validate hsla color format* + ### Module: sanitation * **trim** * **trimLeft** @@ -271,6 +280,684 @@ This plugin comes with translations for English, Polish, Portuguese. You can also choose to override the error dialogs yourself. Here you can read more about [localization](http://formvalidator.net/#localization) +# Default validators + +### Answer length (required) + +``` + + + + + + + + + + + + + + + + +``` +This plugin also supports the attributes "required" and "maxlength" by using the Html5 module. + +### Numbers +``` + + + + + + + + + + + + + + + + + + + + +You can also define the decimal separator when initializing the validation. + +
+ Average points
+
+
+ History (50 characters left) + +
+ +``` +### Make validation optional +``` + + +``` +You can also use the logic module if you want the validation of an input depend on another input having a value. + +### Display help text +It is possible to display help information beside each input. The text will fade in when the input gets focus on and fade out when the input looses focus. The container for the help text will have the class form-help. If you don't want this feature you can read the setup guide on how to disable it. + +``` + + ``` +### Validate inputs when blurred + +By default each input will become validated immediately when the input looses focus. If you don't want this feature you can read the setup guide on how to disable it. + +### Input suggestions +There are two ways you can give suggestions to the user while the user types. + +1) Using attribute data-suggestions + +``` ++ What's your favorite color? + +
+ ... + +``` +2) Using $.formUtils.suggest() +``` + +``` +This plugin also supports the data-list element by using the Html5 module. + +Ignoring characters +You can tell any validator to ignore certain characters by using the attribute data-validation-ignore (comma separated list). +``` ++ How much do you want to donate? + + +
+``` + +## Security validators< + +### Password confirmation + +This validator can be used to validate that the values of two inputs are the same. The first input should have a name suffixed with _confirmation and the second should have the same name but without the suffix. + +``` ++ Password (at least 8 characters) + + + Confirm password + +
+``` + +``` ++ E-mail + + + Repeat e-mail + +
+``` + +### Password strength + +Use this validator to make sure that your user has a strong enough password. Set attributedata-validation-strength
to 1, 2 or 3 depending on how strong password you require.
+
+If you want the strength of the password to be displayed while the user types you call displayPasswordStrength()
in the end of the form.
+
+```
+
+
+
+
+
+```
+
+### Server side validation
+
+By using this validator you can validate the value given by the user on the server before the form gets submitted. The validation function will send a POST request to the URL declared in data-validation-url
. The argument posted to the URL will have the same name as the input being validated.
+
+The form will get the class validating-server-side while the server is being requested.
+
+The response from the validation script must be a JSON formatted object, containing the properties "valid" and "message".
+
+```
+{
+ "valid" : true|false,
+ "message" : "String with text that should be displayed as error message"
+}
+```
+
+#### Form
+
+```
+
+```
+
+#### /validate-input.php
+
+```
+ false,
+ 'message' => 'Post argument "user" is missing.'
+);
+
+if( isset($_POST['user']) ) {
+ $userRepo = new UserRepository( DataStorage::instance() );
+ $user = $userRepo->loadUser( $_POST['user'] );
+
+ if( $user ) {
+ // User name is registered on another account
+ $response = array('valid' => false, 'message' => 'This user name is already registered.');
+ } else {
+ // User name is available
+ $response = array('valid' => true);
+ }
+}
+echo json_encode($response);
+```
+
+**Modifying the server request**
+
+The parameter containing the input value, sent to the server, will by default have the same name as the input. You can however set your own parameter name by using the attribute data-validation-param-name
. You can also send along other parameters to the server by using the attribute data-validation-req-params
.
+
+```
+$user->get('ID')));
+?>
++ E-mail: + +
+``` + +### Credit card validation + +This validator makes it possible to validate any of the credit cards VISA, Mastercard, Diners club, Maestro, CJB, Discover and American express + +``` +<-- Accept credit card number from Visa, Mastercard and American Express --> ++ Credit card number + +
++ Security code (cvv) + +
+``` + +You can also let the user choose a credit card and programmatically change the allowed credit card on the input of the card number. + +``` ++ Credit card + +
++ Credit card number + +
+... + + +``` + +### Simple captcha + +``` + + +``` + +### Google reCAPTCHA + +Use this validator if wanting to integrate the Google service reCAPTCHA. + +``` ++ +
+``` + +You can also use the setup function to configure the recaptcha service. + +``` +$.validate({ + reCaptchaSiteKey: '...', + reCaptchaTheme: 'light' +}); +``` + +### Letters and numbers + +By using the validatorletternumeric
you can validate that given input value only contains letters and/or numbers. This validator allows any type of character in contrast to the alphanumeric validator, which only allows letters A-Z.
+
+```
+
+
+
+
+
+```
+
+## Date validators
+
+### Birthdate
+
+This validator is the same as the default date validator except that it only allows past dates and dates that is not older than 120 years.
+
+```
+
+
+
+
+
+
+
+
+```
+
+## Time
+
+```
+
+
+```
+
+
+## Location validators
+
+### Country
+
+```
+
+
+```
+
+### State (US)
+
+```
+
+
+```
+
+### Longitude and Latitude
+
+```
+
+
+```
+
+### Suggest country/state
+
+By using this function you'll make it easier for your visitor to input a country or state.
+
+```
+
+
+
+
+
+```
+
+## File validators
+
+### File size
+
+This validation is only supported by Internet Explorer 10, Mozilla FireFox v >= 3.6 and any of the later versions of webkit based browsers.
+
+```
+
+
+
+
+
+```
+
+### File type
+
+This validation will fall back on checking the file extension in older browsers. In modern browsers the validation will check that any of the extensions in data-validation-allowing
exists in the mime type declaration of the file. This means that data-validation-allowing="pdf"
will work in both modern browsers (checking against "application/pdf") and older browsers (checking the file extension ".pdf").
+
+```
+
+
+
+
+
+```
+
+Validating multiple files (with separate error messages depending on failed validation):
+
+```
+
+```
+
+### Image dimension and ratio
+
+Use the validator dimension
to check the dimension of an image (jpg, gif or png).
+
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+Use the attribute data-validation-ratio
to validate that the uploaded image has a certain ratio
+
+```
+
+
+
+
+
+```
+
+## Logic
+
+### Validators depending on each other
+
+Use the attributes data-validation-depends-on
to configure that an input is optional as long as another input is left without an answer.
+
+```
+
++ Contact me: + +
++ E-mail: + +
+``` + +``` + ++ Country: + +
+ ++ State: + +
+ +... + + + +``` + +### Require only one out of several inputs + +Use the attributedata-validation-optional-if-answered
to tell the validator that only one, out of a group of inputs, requires an answer.
+
+```
++ Home phone number: + +
++ Cell phone number: + +
++ Work phone number: + +
+ +``` + ## Changelog #### 2.3.19 diff --git a/form-validator/brazil.js b/form-validator/brazil.js index 7f97863..12d9e1b 100644 --- a/form-validator/brazil.js +++ b/form-validator/brazil.js @@ -1,9 +1,9 @@ /** File generated by Grunt -- do not modify * JQUERY-FORM-VALIDATOR * - * @version 2.3.52 + * @version 2.3.79 * @website http://formvalidator.net/ * @author Victor Jonsson, http://victorjonsson.se * @license MIT */ -!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(a){return b(a)}):"object"==typeof exports?module.exports=b(require("jquery")):b(jQuery)}(this,function(a){$.formUtils.addValidator({name:"cpf",validatorFunction:function(a){var b=a.replace(/\D/g,""),c=0,d=0,e=0,f=0;if(11!==b.length||"00000000000"===b)return!1;for(i=1;i<=9;i++)c+=parseInt(b.substring(i-1,i))*(11-i);if(e=10*c%11,e>=10&&(e=0),e!==parseInt(b.substring(9,10)))return!1;for(i=1;i<=10;i++)d+=parseInt(b.substring(i-1,i))*(12-i);return f=10*d%11,f>=10&&(f=0),f===parseInt(b.substring(10,11))},errorMessage:"",errorMessageKey:"badBrazilCPFAnswer"}),$.formUtils.addValidator({name:"brphone",validatorFunction:function(a){return!!a.match(/^(\+[\d]{1,3}[\s]{0,1}){0,1}(\(){0,1}(\d){2}(\)){0,1}(\s){0,1}(\d){4,5}([-. ]){0,1}(\d){4}$/g)},errorMessage:"",errorMessageKey:"badBrazilTelephoneAnswer"}),$.formUtils.addValidator({name:"cep",validatorFunction:function(a){return!!a.match(/^(\d){5}([-. ]){0,1}(\d){3}$/g)},errorMessage:"",errorMessageKey:"badBrazilCEPAnswer"})}); \ No newline at end of file +!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(a){return b(a)}):"object"==typeof module&&module.exports?module.exports=b(require("jquery")):b(a.jQuery)}(this,function(a){!function(a){a.formUtils.registerLoadedModule("brazil"),a.formUtils.addValidator({name:"cpf",validatorFunction:function(a){var b=a.replace(/\D/g,""),c=0,d=0,e=0,f=0;if(11!==b.length||"00000000000"===b)return!1;for(i=1;i<=9;i++)c+=parseInt(b.substring(i-1,i))*(11-i);if(e=10*c%11,e>=10&&(e=0),e!==parseInt(b.substring(9,10)))return!1;for(i=1;i<=10;i++)d+=parseInt(b.substring(i-1,i))*(12-i);return f=10*d%11,f>=10&&(f=0),f===parseInt(b.substring(10,11))},errorMessage:"",errorMessageKey:"badBrazilCPFAnswer"}),a.formUtils.addValidator({name:"brphone",validatorFunction:function(a){return!!a.match(/^(\+[\d]{1,3}[\s]{0,1}){0,1}(\(){0,1}(\d){2}(\)){0,1}(\s){0,1}(\d){4,5}([-. ]){0,1}(\d){4}$/g)},errorMessage:"",errorMessageKey:"badBrazilTelephoneAnswer"}),a.formUtils.addValidator({name:"cep",validatorFunction:function(a){return!!a.match(/^(\d){5}([-. ]){0,1}(\d){3}$/g)},errorMessage:"",errorMessageKey:"badBrazilCEPAnswer"})}(a)}); \ No newline at end of file diff --git a/form-validator/color.js b/form-validator/color.js new file mode 100644 index 0000000..b7f8a17 --- /dev/null +++ b/form-validator/color.js @@ -0,0 +1,9 @@ +/** File generated by Grunt -- do not modify + * JQUERY-FORM-VALIDATOR + * + * @version 2.3.79 + * @website http://formvalidator.net/ + * @author Victor Jonsson, http://victorjonsson.se + * @license MIT + */ +!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(a){return b(a)}):"object"==typeof module&&module.exports?module.exports=b(require("jquery")):b(a.jQuery)}(this,function(a){!function(a){a.formUtils.registerLoadedModule("color");var b=function(a){return/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/.test(a)?Number(a):NaN},c=function(a){return a>0&&a<1},d=function(b){return Math.floor(b)===b&&a.isNumeric(b)};a.formUtils.addValidator({name:"hex",validatorFunction:function(a,b){if("true"===b.valAttr("allow-transparent")&&"transparent"===a)return!0;var c="#"===a[0];if(!c)return!1;var d=4===a.length||7===a.length;if(d){var e=/[0-9a-f]/i,f=a.slice(1).split(""),g=!0;return f.forEach(function(a){null===a.match(e)&&(g=!1)}),g}return!1},errorMessage:"",errorMessageKey:"badHex"}),a.formUtils.addValidator({name:"rgb",validatorFunction:function(a,b){if("true"===b.valAttr("allow-transparent")&&"transparent"===a)return!0;var c=a.replace(/ /g,""),e=/rgb\([0-9]{1,3},[0-9]{1,3},[0-9]{1,3}\)/i;if(c.match(e)){var f=c.replace(/rgb/g,""),g=f.replace(/\(/g,"").replace(/\)/g,""),h=g.split(","),i=!0;return h.forEach(function(a){var b=parseInt(a,10);(d(b)&&0<=b&&b<=255)===!1&&(i=!1)}),i}return!1},errorMessage:"",errorMessageKey:"badRgb"}),a.formUtils.addValidator({name:"rgba",validatorFunction:function(a,e){if("true"===e.valAttr("allow-transparent")&&"transparent"===a)return!0;var f=a.replace(/ /g,""),g=/rgba\([0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0,1]?.?[0-9]*\)/i;if(f.match(g)){var h=f.replace(/rgba/g,""),i=h.replace(/\(/g,"").replace(/\)/g,""),j=i.split(","),k=!0;return j.forEach(function(a,e){var f=b(a);if(d(f)){var g=f>=0&&f<=255;g||(k=!1),k&&3===e&&(k=f>=0&&f<2)}else c(a)||(k=!1)}),k}return!1},errorMessage:"",errorMessageKey:"badRgba"}),a.formUtils.addValidator({name:"hsl",validatorFunction:function(a,b){if("true"===b.valAttr("allow-transparent")&&"transparent"===a)return!0;var c=a.replace(/ /g,""),e=/hsl\(-?[0-9]{1,3},[0-9]{1,3}%,[0-9]{1,3}%\)/i;if(c.match(e)){var f=c.replace(/hsl/g,""),g=f.replace(/\(/g,"").replace(/\)/g,""),h=g.split(","),i=!0;return h.forEach(function(a,b){var c=parseInt(a,10);if(d(c)){if(0!==b){var e=c>=0&&c<=100;e||(i=!1)}}else i=!1}),i}return!1},errorMessage:"",errorMessageKey:"badHsl"}),a.formUtils.addValidator({name:"hsla",validatorFunction:function(a,c){if("true"===c.valAttr("allow-transparent")&&"transparent"===a)return!0;var e,f=a.replace(/ /g,""),g=/hsla\(-?[0-9]{1,3},[0-9]{1,3}%,[0-9]{1,3}%,[0,1]?.?[0-9]*\)/i;if(f.match(g)){var h=f.replace(/hsla/g,""),i=h.replace(/\(/g,"").replace(/\)/g,""),j=i.split(","),k=!0;return j.forEach(function(a,c){var f=b(a),g=parseInt(a,10);d(f)?(0!==c&&3!==c&&(e=f>=0&&f<=100,e||(k=!1)),k&&3===c&&(k=f>=0&&f<2)):isNaN(f)&&d(g)?(e=g>=0&&g<=100,e||(k=!1)):(f=b(Number(a).toFixed(20)),e=f>=0&&f<=1,e||(k=!1))}),k}return!1},errorMessage:"",errorMessageKey:"badHsla"})}(a)}); \ No newline at end of file diff --git a/form-validator/date.js b/form-validator/date.js index e4f2929..ad744d3 100644 --- a/form-validator/date.js +++ b/form-validator/date.js @@ -1,9 +1,9 @@ /** File generated by Grunt -- do not modify * JQUERY-FORM-VALIDATOR * - * @version 2.3.52 + * @version 2.3.79 * @website http://formvalidator.net/ * @author Victor Jonsson, http://victorjonsson.se * @license MIT */ -!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],function(a){return b(a)}):"object"==typeof exports?module.exports=b(require("jquery")):b(jQuery)}(this,function(a){!function(a){a.formUtils.addValidator({name:"time",validatorFunction:function(a){if(null===a.match(/^(\d{2}):(\d{2})$/))return!1;var b=parseInt(a.split(":")[0],10),c=parseInt(a.split(":")[1],10);return!(b>23||c>59)},errorMessage:"",errorMessageKey:"badTime"}),a.formUtils.addValidator({name:"birthdate",validatorFunction:function(b,c,d){var e="yyyy-mm-dd";c.valAttr("format")?e=c.valAttr("format"):"undefined"!=typeof d.dateFormat&&(e=d.dateFormat);var f=a.formUtils.parseDate(b,e);if(!f)return!1;var g=new Date,h=g.getFullYear(),i=f[0],j=f[1],k=f[2];if(i===h){var l=g.getMonth()+1;if(j===l){var m=g.getDate();return k<=m}return j