Skip to content

Commit

Permalink
Merge pull request #21 from xael-fry/20_updateJqueryVal1.16
Browse files Browse the repository at this point in the history
* [#20] chore(lib): update to jquery validate 1.16
  • Loading branch information
xael-fry authored Mar 13, 2017
2 parents 69f504b + 22b36fb commit cda6075
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 117 deletions.
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jqvalidate",
"version": "1.0.5",
"version": "1.0.7",
"homepage": "https://github.com/xael-fry/play-jqvalidate",
"repository": {
"type": "git",
Expand All @@ -24,7 +24,7 @@
"tests"
],
"dependencies": {
"jquery-validation": "1.15.0"
"jquery-validation": "1.16.0"
},
"install" : {
"path" : "bower_components"
Expand Down
2 changes: 1 addition & 1 deletion conf/dependencies.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
self: play -> jqvalidate 1.6
self: play -> jqvalidate 1.7

require:
- play
Binary file modified lib/play-jqvalidate.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "jqvalidate",
"version": "1.0.6",
"version": "1.0.7",
"description": "Client-side form validation based on your Play framework model annotations.",
"dependencies": {},
"devDependencies": {
"grunt": "1.0.1",
"grunt-contrib-jshint": "1.1.0",
"grunt-contrib-uglify": "2.0.0",
"grunt-contrib-uglify": "2.1.0",
"grunt-compare-size": "0.4.2",
"grunt-bowercopy": "1.2.4"
},
Expand Down
254 changes: 160 additions & 94 deletions public/javascripts/additional-methods.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* jQuery Validation Plugin v1.15.0
* jQuery Validation Plugin v1.16.0
*
* http://jqueryvalidation.org/
*
Expand Down Expand Up @@ -48,8 +48,8 @@ $.validator.addMethod( "accept", function( value, element, param ) {

// Split mime on commas in case we have multiple types we can accept
var typeParam = typeof param === "string" ? param.replace( /\s/g, "" ) : "image/*",
optionalValue = this.optional( element ),
i, file, regex;
optionalValue = this.optional( element ),
i, file, regex;

// Element is optional
if ( optionalValue ) {
Expand All @@ -61,7 +61,10 @@ $.validator.addMethod( "accept", function( value, element, param ) {
// Escape string to be used in the regex
// see: http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
// Escape also "/*" as "/.*" as a wildcard
typeParam = typeParam.replace( /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g, "\\$&" ).replace( /,/g, "|" ).replace( "\/*", "/.*" );
typeParam = typeParam
.replace( /[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g, "\\$&" )
.replace( /,/g, "|" )
.replace( /\/\*/g, "/.*" );

// Check if the element has a FileList before checking each file
if ( element.files && element.files.length ) {
Expand Down Expand Up @@ -141,59 +144,111 @@ $.validator.addMethod( "bic", function( value, element ) {
/*
* Código de identificación fiscal ( CIF ) is the tax identification code for Spanish legal entities
* Further rules can be found in Spanish on http://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
*
* Spanish CIF structure:
*
* [ T ][ P ][ P ][ N ][ N ][ N ][ N ][ N ][ C ]
*
* Where:
*
* T: 1 character. Kind of Organization Letter: [ABCDEFGHJKLMNPQRSUVW]
* P: 2 characters. Province.
* N: 5 characters. Secuencial Number within the province.
* C: 1 character. Control Digit: [0-9A-J].
*
* [ T ]: Kind of Organizations. Possible values:
*
* A. Corporations
* B. LLCs
* C. General partnerships
* D. Companies limited partnerships
* E. Communities of goods
* F. Cooperative Societies
* G. Associations
* H. Communities of homeowners in horizontal property regime
* J. Civil Societies
* K. Old format
* L. Old format
* M. Old format
* N. Nonresident entities
* P. Local authorities
* Q. Autonomous bodies, state or not, and the like, and congregations and religious institutions
* R. Congregations and religious institutions (since 2008 ORDER EHA/451/2008)
* S. Organs of State Administration and regions
* V. Agrarian Transformation
* W. Permanent establishments of non-resident in Spain
*
* [ C ]: Control Digit. It can be a number or a letter depending on T value:
* [ T ] --> [ C ]
* ------ ----------
* A Number
* B Number
* E Number
* H Number
* K Letter
* P Letter
* Q Letter
* S Letter
*
*/
$.validator.addMethod( "cifES", function( value ) {
"use strict";

var num = [],
controlDigit, sum, i, count, tmp, secondDigit;

value = value.toUpperCase();
var cifRegEx = new RegExp( /^([ABCDEFGHJKLMNPQRSUVW])(\d{7})([0-9A-J])$/gi );
var letter = value.substring( 0, 1 ), // [ T ]
number = value.substring( 1, 8 ), // [ P ][ P ][ N ][ N ][ N ][ N ][ N ]
control = value.substring( 8, 9 ), // [ C ]
all_sum = 0,
even_sum = 0,
odd_sum = 0,
i, n,
control_digit,
control_letter;

function isOdd( n ) {
return n % 2 === 0;
}

// Quick format test
if ( !value.match( "((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)" ) ) {
if ( value.length !== 9 || !cifRegEx.test( value ) ) {
return false;
}

for ( i = 0; i < 9; i++ ) {
num[ i ] = parseInt( value.charAt( i ), 10 );
}
for ( i = 0; i < number.length; i++ ) {
n = parseInt( number[ i ], 10 );

// Odd positions
if ( isOdd( i ) ) {

// Algorithm for checking CIF codes
sum = num[ 2 ] + num[ 4 ] + num[ 6 ];
for ( count = 1; count < 8; count += 2 ) {
tmp = ( 2 * num[ count ] ).toString();
secondDigit = tmp.charAt( 1 );
// Odd positions are multiplied first.
n *= 2;

sum += parseInt( tmp.charAt( 0 ), 10 ) + ( secondDigit === "" ? 0 : parseInt( secondDigit, 10 ) );
// If the multiplication is bigger than 10 we need to adjust
odd_sum += n < 10 ? n : n - 9;

// Even positions
// Just sum them
} else {
even_sum += n;
}
}

/* The first (position 1) is a letter following the following criteria:
* A. Corporations
* B. LLCs
* C. General partnerships
* D. Companies limited partnerships
* E. Communities of goods
* F. Cooperative Societies
* G. Associations
* H. Communities of homeowners in horizontal property regime
* J. Civil Societies
* K. Old format
* L. Old format
* M. Old format
* N. Nonresident entities
* P. Local authorities
* Q. Autonomous bodies, state or not, and the like, and congregations and religious institutions
* R. Congregations and religious institutions (since 2008 ORDER EHA/451/2008)
* S. Organs of State Administration and regions
* V. Agrarian Transformation
* W. Permanent establishments of non-resident in Spain
*/
if ( /^[ABCDEFGHJNPQRSUVW]{1}/.test( value ) ) {
sum += "";
controlDigit = 10 - parseInt( sum.charAt( sum.length - 1 ), 10 );
value += controlDigit;
return ( num[ 8 ].toString() === String.fromCharCode( 64 + controlDigit ) || num[ 8 ].toString() === value.charAt( value.length - 1 ) );
all_sum = even_sum + odd_sum;
control_digit = ( 10 - ( all_sum ).toString().substr( -1 ) ).toString();
control_digit = parseInt( control_digit, 10 ) > 9 ? "0" : control_digit;
control_letter = "JABCDEFGHI".substr( control_digit, 1 ).toString();

// Control must be a digit
if ( letter.match( /[ABEH]/ ) ) {
return control === control_digit;

// Control must be a letter
} else if ( letter.match( /[KPQS]/ ) ) {
return control === control_letter;

// Can be either
} else {
return control === control_digit || control === control_letter;
}

return false;
Expand Down Expand Up @@ -496,6 +551,16 @@ $.validator.addMethod( "iban", function( value, element ) {
cOperator = "",
countrycode, ibancheck, charAt, cChar, bbanpattern, bbancountrypatterns, ibanregexp, i, p;

// Check for IBAN code length.
// It contains:
// country code ISO 3166-1 - two letters,
// two check digits,
// Basic Bank Account Number (BBAN) - up to 30 chars
var minimalIBANlength = 5;
if ( iban.length < minimalIBANlength ) {
return false;
}

// Check the country code and find the country specific format
countrycode = iban.substring( 0, 2 );
bbancountrypatterns = {
Expand Down Expand Up @@ -641,37 +706,38 @@ $.validator.addMethod( "mobileUK", function( phone_number, element ) {
}, "Please specify a valid mobile number" );

/*
* The número de identidad de extranjero ( NIE )is a code used to identify the non-nationals in Spain
* The NIE (Número de Identificación de Extranjero) is a Spanish tax identification number assigned by the Spanish
* authorities to any foreigner.
*
* The NIE is the equivalent of a Spaniards Número de Identificación Fiscal (NIF) which serves as a fiscal
* identification number. The CIF number (Certificado de Identificación Fiscal) is equivalent to the NIF, but applies to
* companies rather than individuals. The NIE consists of an 'X' or 'Y' followed by 7 or 8 digits then another letter.
*/
$.validator.addMethod( "nieES", function( value ) {
"use strict";

value = value.toUpperCase();
var nieRegEx = new RegExp( /^[MXYZ]{1}[0-9]{7,8}[TRWAGMYFPDXBNJZSQVHLCKET]{1}$/gi );
var validChars = "TRWAGMYFPDXBNJZSQVHLCKET",
letter = value.substr( value.length - 1 ).toUpperCase(),
number;

// Basic format test
if ( !value.match( "((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)" ) ) {
value = value.toString().toUpperCase();

// Quick format test
if ( value.length > 10 || value.length < 9 || !nieRegEx.test( value ) ) {
return false;
}

// Test NIE
//T
if ( /^[T]{1}/.test( value ) ) {
return ( value[ 8 ] === /^[T]{1}[A-Z0-9]{8}$/.test( value ) );
}
// X means same number
// Y means number + 10000000
// Z means number + 20000000
value = value.replace( /^[X]/, "0" )
.replace( /^[Y]/, "1" )
.replace( /^[Z]/, "2" );

//XYZ
if ( /^[XYZ]{1}/.test( value ) ) {
return (
value[ 8 ] === "TRWAGMYFPDXBNJZSQVHLCKE".charAt(
value.replace( "X", "0" )
.replace( "Y", "1" )
.replace( "Z", "2" )
.substring( 0, 8 ) % 23
)
);
}
number = value.length === 9 ? value.substr( 0, 8 ) : value.substr( 0, 9 );

return false;
return validChars.charAt( parseInt( number, 10 ) % 23 ) === letter;

}, "Please specify a valid NIE number." );

Expand Down Expand Up @@ -702,7 +768,7 @@ $.validator.addMethod( "nifES", function( value ) {

}, "Please specify a valid NIF number." );

jQuery.validator.addMethod( "notEqualTo", function( value, element, param ) {
$.validator.addMethod( "notEqualTo", function( value, element, param ) {
return this.optional( element ) || !$.validator.methods.equalTo.call( this, value, element, param );
}, "Please enter a different value, values must not be the same." );

Expand Down Expand Up @@ -740,6 +806,22 @@ $.validator.addMethod( "phoneNL", function( value, element ) {
return this.optional( element ) || /^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9]){8}$/.test( value );
}, "Please specify a valid phone number." );

/* For UK phone functions, do the following server side processing:
* Compare original input with this RegEx pattern:
* ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
* Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
* Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
* A number of very detailed GB telephone number RegEx patterns can also be found at:
* http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
*/

// Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers
$.validator.addMethod( "phonesUK", function( phone_number, element ) {
phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );
return this.optional( element ) || phone_number.length > 9 &&
phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/ );
}, "Please specify a valid uk phone number" );

/* For UK phone functions, do the following server side processing:
* Compare original input with this RegEx pattern:
* ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
Expand Down Expand Up @@ -776,21 +858,17 @@ $.validator.addMethod( "phoneUS", function( phone_number, element ) {
phone_number.match( /^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]([02-9]\d|1[02-9])-?\d{4}$/ );
}, "Please specify a valid phone number" );

/* For UK phone functions, do the following server side processing:
* Compare original input with this RegEx pattern:
* ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$
* Extract $1 and set $prefix to '+44<space>' if $1 is '44', otherwise set $prefix to '0'
* Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2.
* A number of very detailed GB telephone number RegEx patterns can also be found at:
* http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers
*/

// Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers
$.validator.addMethod( "phonesUK", function( phone_number, element ) {
phone_number = phone_number.replace( /\(|\)|\s+|-/g, "" );
return this.optional( element ) || phone_number.length > 9 &&
phone_number.match( /^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/ );
}, "Please specify a valid uk phone number" );
/*
* Valida CEPs do brasileiros:
*
* Formatos aceitos:
* 99999-999
* 99.999-999
* 99999999
*/
$.validator.addMethod( "postalcodeBR", function( cep_value, element ) {
return this.optional( element ) || /^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test( cep_value );
}, "Informe um CEP válido." );

/**
* Matches a valid Canadian Postal Code
Expand All @@ -809,18 +887,6 @@ $.validator.addMethod( "postalCodeCA", function( value, element ) {
return this.optional( element ) || /^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] *\d[ABCEGHJKLMNPRSTVWXYZ]\d$/i.test( value );
}, "Please specify a valid postal code" );

/*
* Valida CEPs do brasileiros:
*
* Formatos aceitos:
* 99999-999
* 99.999-999
* 99999999
*/
$.validator.addMethod( "postalcodeBR", function( cep_value, element ) {
return this.optional( element ) || /^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test( cep_value );
}, "Informe um CEP válido." );

/* Matches Italian postcode (CAP) */
$.validator.addMethod( "postalcodeIT", function( value, element ) {
return this.optional( element ) || /^\d{5}$/.test( value );
Expand Down Expand Up @@ -1052,5 +1118,5 @@ $.validator.addMethod( "zipcodeUS", function( value, element ) {
$.validator.addMethod( "ziprange", function( value, element ) {
return this.optional( element ) || /^90[2-5]\d\{2\}-\d{4}$/.test( value );
}, "Your ZIP-code must be in the range 902xx-xxxx to 905xx-xxxx" );

return $;
}));
4 changes: 2 additions & 2 deletions public/javascripts/additional-methods.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit cda6075

Please sign in to comment.