Skip to content

phonePL validation method #2136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/additional/phonePL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Polish telephone numbers have 9 digits.
*
* Mobile phone numbers starts with following digits:
* 45, 50, 51, 53, 57, 60, 66, 69, 72, 73, 78, 79, 88.
*
* Fixed-line numbers starts with area codes:
* 12, 13, 14, 15, 16, 17, 18, 22, 23, 24, 25, 29, 32, 33,
* 34, 41, 42, 43, 44, 46, 48, 52, 54, 55, 56, 58, 59, 61,
* 62, 63, 65, 67, 68, 71, 74, 75, 76, 77, 81, 82, 83, 84,
* 85, 86, 87, 89, 91, 94, 95.
*
* Ministry of National Defence numbers and VoIP numbers starts with 26 and 39.
*
* Excludes intelligent networks (premium rate, shared cost, free phone numbers).
*
* Poland National Numbering Plan http://www.itu.int/oth/T02020000A8/en
*/
$.validator.addMethod( "phonePL", function( phone_number, element ) {
phone_number = phone_number.replace( /\s+/g, "" );
var regexp = /^(?:(?:(?:\+|00)?48)|(?:\(\+?48\)))?(?:1[2-8]|2[2-69]|3[2-49]|4[1-68]|5[0-9]|6[0-35-9]|[7-8][1-9]|9[145])\d{7}$/;
return this.optional( element ) || regexp.test( phone_number );
}, "Please specify a valid phone number" );
1 change: 1 addition & 0 deletions src/localization/messages_pl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $.extend( $.validator.messages, {
equalTo: "Proszę o podanie tej samej wartości ponownie.",
extension: "Proszę o podanie wartości z prawidłowym rozszerzeniem.",
nipPL: "Proszę o podanie prawidłowego numeru NIP.",
phonePL: "Proszę o podanie prawidłowego numeru telefonu",
maxlength: $.validator.format( "Proszę o podanie nie więcej niż {0} znaków." ),
minlength: $.validator.format( "Proszę o podanie przynajmniej {0} znaków." ),
rangelength: $.validator.format( "Proszę o podanie wartości o długości od {0} do {1} znaków." ),
Expand Down
18 changes: 18 additions & 0 deletions test/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,24 @@ QUnit.test( "nipPL", function( assert ) {
assert.ok( !method( "9502947712" ), "NIP invalid: wrong checksum" );
} );

QUnit.test( "phonePL", function( assert ) {
var method = methodTest( "phonePL" );
assert.ok( method( "+48 123 456 789" ), "Valid phone PL" );
assert.ok( method( "00 48 123 456 789" ), "Valid phone PL" );
assert.ok( method( "(+48) 123 456 789" ), "Valid phone PL" );
assert.ok( method( "(48) 123 456 789" ), "Valid phone PL" );
assert.ok( method( " 13 34 56 78 9 " ), "Valid phone PL" );
assert.ok( method( "13 345 67 89" ), "Valid phone PL" );
assert.ok( !method( "100 000 000" ), "Invalid phone PL: cannot start with 10x xxx xxx" );
assert.ok( !method( "111 111 111" ), "Invalid phone PL: cannot start with 11x xxx xxx" );
assert.ok( !method( "123 456 78" ), "Invalid phone PL: too short" );
assert.ok( !method( "123 4567890" ), "Invalid phone PL: too long" );
assert.ok( !method( "700 123 456" ), "Invalid phone PL: intelligent network, premium rate" );
assert.ok( !method( "800 123 456" ), "Invalid phone PL: intelligent network, freephone" );
assert.ok( !method( "980 000 000" ), "Invalid phone PL: cannot start with 98x xxx xxx" );
assert.ok( !method( "990 000 000" ), "Invalid phone PL: cannot start with 99x xxx xxx" );
} );

QUnit.test( "maxWords", function( assert ) {
var method = methodTest( "maxWords" ),
maxWords = 6;
Expand Down