diff --git a/.gitignore b/.gitignore index de4d1f007..a284d1362 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dist node_modules +.idea diff --git a/package.json b/package.json index 866149d42..e1bc130aa 100644 --- a/package.json +++ b/package.json @@ -1,60 +1,60 @@ { - "name": "jquery-validation", - "title": "jQuery Validation Plugin", - "description": "Client-side form validation made easy", - "version": "1.15.2-pre", - "homepage": "http://jqueryvalidation.org/", - "license": "MIT", - "author": { - "name": "Jörn Zaefferer", - "email": "joern.zaefferer@gmail.com", - "url": "http://bassistance.de" - }, - "repository": { - "type": "git", - "url": "git://github.com/jzaefferer/jquery-validation.git" - }, - "bugs": { - "url": "https://github.com/jzaefferer/jquery-validation/issues" - }, - "licenses": [ - { - "type": "MIT", - "url": "http://www.opensource.org/licenses/MIT" - } - ], - "scripts": { - "test": "grunt", - "prepublish": "grunt" - }, - "files": [ - "dist/localization/", - "dist/additional-methods.js", - "dist/jquery.validate.js" - ], - "main": "dist/jquery.validate.js", - "dependencies": { - "jquery": "^1.7 || ^2.0" - }, - "devDependencies": { - "commitplease": "2.3.1", - "grunt": "1.0.1", - "grunt-contrib-compress": "1.2.0", - "grunt-contrib-concat": "1.0.1", - "grunt-contrib-copy": "1.0.0", - "grunt-contrib-jshint": "1.0.0", - "grunt-contrib-qunit": "1.2.0", - "grunt-contrib-uglify": "1.0.1", - "grunt-contrib-watch": "1.0.0", - "grunt-jscs": "2.8.0", - "grunt-text-replace": "0.4.0", - "qunitjs": "2.0.0" - }, - "keywords": [ - "jquery", - "jquery-plugin", - "forms", - "validation", - "validate" - ] + "name": "jquery-validation", + "title": "jQuery Validation Plugin", + "description": "Client-side form validation made easy", + "version": "1.15.2-pre", + "homepage": "http://jqueryvalidation.org/", + "license": "MIT", + "author": { + "name": "Jörn Zaefferer", + "email": "joern.zaefferer@gmail.com", + "url": "http://bassistance.de" + }, + "repository": { + "type": "git", + "url": "git://github.com/jzaefferer/jquery-validation.git" + }, + "bugs": { + "url": "https://github.com/jzaefferer/jquery-validation/issues" + }, + "licenses": [ + { + "type": "MIT", + "url": "http://www.opensource.org/licenses/MIT" + } + ], + "scripts": { + "test": "grunt", + "prepublish": "grunt" + }, + "files": [ + "dist/localization/", + "dist/additional-methods.js", + "dist/jquery.validate.js" + ], + "main": "dist/jquery.validate.js", + "dependencies": { + "jquery": "^1.7 || ^2.0" + }, + "devDependencies": { + "commitplease": "2.3.1", + "grunt": "1.0.1", + "grunt-contrib-compress": "1.2.0", + "grunt-contrib-concat": "1.0.1", + "grunt-contrib-copy": "1.0.0", + "grunt-contrib-jshint": "1.0.0", + "grunt-contrib-qunit": "1.2.0", + "grunt-contrib-uglify": "^2.0.0", + "grunt-contrib-watch": "1.0.0", + "grunt-jscs": "2.8.0", + "grunt-text-replace": "0.4.0", + "qunitjs": "2.0.0" + }, + "keywords": [ + "jquery", + "jquery-plugin", + "forms", + "validation", + "validate" + ] } diff --git a/src/additional/nisBR.js b/src/additional/nisBR.js new file mode 100644 index 000000000..dabcc0cf2 --- /dev/null +++ b/src/additional/nisBR.js @@ -0,0 +1,59 @@ +/** + * Created for project jquery-validation. + * @Description Brazillian PIS or NIS number (Número de Identificação Social Pis ou Pasep) is the equivalent of a + * Brazilian tax registration number NIS of PIS numbers have 11 digits in total: 10 numbers followed by 1 check numbers + * that are being used for validation. + * @copyright (c) 25/10/2016 22:40, Cleiton da Silva Mendonça + * @author Cleiton da Silva Mendonça + * @link http://gitlab.com/csmendonca Gitlab of Cleiton da Silva Mendonça + * @link http://github.com/csmendonca Github of Cleiton da Silva Mendonça + */ + +$.validator.addMethod( "nisBR", function( value ) { + + var number; + var cn; + var sum = 0; + var dv; + var count; + var multiplier; + + // Removing special characters from value + value = value.replace( /([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g, "" ); + + // Checking value to have 11 digits only + if ( value.length !== 11 ) { + return false; + } + + //Get check number of value + cn = parseInt( value.substring( 10, 11 ), 10 ); + + //Get number with 10 digits of the value + number = parseInt( value.substring( 0, 10 ), 10 ); + + for ( count = 2; count < 12; count++ ) { + multiplier = count; + if ( count === 10 ) { + multiplier = 2; + } + if ( count === 11 ) { + multiplier = 3; + } + sum += ( ( number % 10 ) * multiplier ); + number = parseInt( number / 10, 10 ); + } + dv = ( sum % 11 ); + + if ( dv > 1 ) { + dv = ( 11 - dv ); + } else { + dv = 0; + } + + if ( cn === dv ) { + return true; + } else { + return false; + } +}, "Please specify a valid NIS/PIS number" ); diff --git a/src/localization/messages_pt_BR.js b/src/localization/messages_pt_BR.js index a7eeec10c..25c267652 100644 --- a/src/localization/messages_pt_BR.js +++ b/src/localization/messages_pt_BR.js @@ -71,5 +71,6 @@ $.extend( $.validator.messages, { vinUS: "O número de identificação de veículo informada (VIN) é inválido.", zipcodeUS: "Por favor, forneceça um código postal americano válido.", ziprange: "O código postal deve estar entre 902xx-xxxx e 905xx-xxxx", - cpfBR: "Por favor, forneça um CPF válido." + cpfBR: "Por favor, forneça um CPF válido.", + nisBR: "Por favor, forneça um NIS/PIS válido" } ); diff --git a/test/methods.js b/test/methods.js index 0c059f895..aaa55f56a 100644 --- a/test/methods.js +++ b/test/methods.js @@ -1537,3 +1537,16 @@ QUnit.test( "file accept - invalid mime type", function( assert ) { proxy = $.proxy( $.validator.methods.accept, new $.validator( {}, $form[ 0 ] ), null, input, "application/vnd.google-earth.kml+xml" ); assert.equal( proxy(), false, "the selected file for upload has invalid mime type" ); } ); + +QUnit.test( "nisBR", function( assert ) { + var method = methodTest( "nisBR" ); + assert.ok( method( "10757995753" ), "Valid NIS/PIS Number" ); + assert.ok( method( "107.57995.75-3" ), "Valid NIS/PIS Number" ); + assert.ok( method( "107.579.957-53" ), "Valid NIS/PIS Number" ); + assert.ok( method( "107-579-957-53" ), "Valid NIS/PIS Number" ); + assert.ok( method( "107.579.957.5-3" ), "Valid NIS/PIS Number" ); + assert.ok( !method( "99999999999" ), "Invalid NIS/PIS Number: dump data" ); + assert.ok( !method( "1075799575" ), "Invalid NIS/PIS Number: < 11 digits" ); + assert.ok( !method( "111444777355" ), "Invalid NIS/PIS Number: > 11 digits" ); + assert.ok( !method( "10757995752" ), "Invalid NIS/PIS Number: check number failed" ); +} ); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy