Skip to content
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

Added Danish(DK) Phone number #2070

Closed
wants to merge 1 commit into from
Closed

Added Danish(DK) Phone number #2070

wants to merge 1 commit into from

Conversation

BenjaminHoegh
Copy link
Contributor

Matches DK phone number format

allows '-' or ' ' as a separator and allows parens around area code
some people may want to put a '+45' in front of their number

  • +45 21-77-21-77
  • +45 21 77 21 77
  • +45 21772177
  • +4521772177
  • 21 77 21 77
  • 21-77-21-77
  • 2177 2177
  • 2177-2177
  • 21772177

but not

  • +1 3243121212
  • +45 112
  • +452143284233
  • 2143284233

@staabm
Copy link
Member

staabm commented Sep 16, 2017

Please add tests

@BenjaminHoegh
Copy link
Contributor Author

@staabm what do you mean ??? screenshots?

@staabm
Copy link
Member

staabm commented Sep 16, 2017

I mean unit tests, see the tests folder. I also realized we dont have tests for the other languages, so this is not a must have.

@Arkni could you add some example tests for phoneUs so people see a example?

Copy link
Member

@Arkni Arkni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. 2 small changes and we are good to land.

$.validator.addMethod( "phoneDK", function( phone_number, element ) {
phone_number = phone_number.replace( /\s+/g, "" );
return this.optional( element ) || phone_number.length > 9 &&
phone_number.match( /^(\+45( )?)?([0-9]{2})((-| )?[0-9]{2})((-| )?[0-9]{2})((-| )?[0-9]{2})$/ );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use regex.test(string) instead of string.match(regex). We only need to know whether the phone number matches the regex or not. We don't need to retrieve the matched parts.

Also, please use non-capturing instead of capturing groups [1]

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references

Copy link
Contributor Author

@BenjaminHoegh BenjaminHoegh Sep 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay thanks, will look on it later this week

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Arkni can this regex codestyle be enforced via jshint?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None that I am aware of.

@Arkni
Copy link
Member

Arkni commented Sep 17, 2017

@staabm
I will see if I can find a moment to work on them tomorrow.

Tests should not block us from merging this PR though, as @HawkonDK can add them in another PR.

@Arkni
Copy link
Member

Arkni commented Sep 19, 2017

@staabm
Just did a quick read to the test files and I found that tests for phoneUS are already added (phoneUK tests are there too). See

QUnit.test( "phone (us)", function( assert ) {
var method = methodTest( "phoneUS" );
assert.ok( method( "1(212)-999-2345" ), "Valid US phone number" );
assert.ok( method( "212 999 2344" ), "Valid US phone number" );
assert.ok( method( "212-999-0983" ), "Valid US phone number" );
assert.ok( !method( "111-123-5434" ), "Invalid US phone number. Area Code cannot start with 1" );
assert.ok( !method( "212 123 4567" ), "Invalid US phone number. NXX cannot start with 1" );
assert.ok( !method( "234-911-5678" ), "Invalid US phone number, because the exchange code cannot be in the form N11" );
assert.ok( !method( "911-333-5678" ), "Invalid US phone number, because the area code cannot be in the form N11" );
assert.ok( method( "234-912-5678" ), "Valid US phone number" );
} );

@staabm
Copy link
Member

staabm commented Sep 24, 2017

@Arkni awesome, we should separate them into a „additional“ folder and equal named files like the impl then

@Arkni
Copy link
Member

Arkni commented Nov 14, 2017

Hi @HawkonDK
Are you willing to continue working on this?

Thanks!

@BenjaminHoegh BenjaminHoegh mentioned this pull request Apr 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants