From 3d98b54027320b31ba228a5feda7b58ff49578cd Mon Sep 17 00:00:00 2001 From: lilia Date: Fri, 4 Dec 2015 17:21:41 -0800 Subject: [PATCH] Create contact from number with common punctuation The 'Create new contact' option should now appear for numbers including parens and other common punctuation. // FREEBIE --- js/views/conversation_search_view.js | 2 +- test/index.html | 2 ++ test/views/conversation_search_view_test.js | 24 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/views/conversation_search_view_test.js diff --git a/js/views/conversation_search_view.js b/js/views/conversation_search_view.js index 7a04f5f13..a20e33c79 100644 --- a/js/views/conversation_search_view.js +++ b/js/views/conversation_search_view.js @@ -123,7 +123,7 @@ }, maybeNumber: function(number) { - return number.match(/^\+?[0-9]*$/); + return number.replace(/[\s-.\(\)]*/g,'').match(/^\+?[0-9]*$/); } }); diff --git a/test/index.html b/test/index.html index 2dc499d85..372690b38 100644 --- a/test/index.html +++ b/test/index.html @@ -125,11 +125,13 @@ + + diff --git a/test/views/conversation_search_view_test.js b/test/views/conversation_search_view_test.js new file mode 100644 index 000000000..4650df08c --- /dev/null +++ b/test/views/conversation_search_view_test.js @@ -0,0 +1,24 @@ +describe('ConversationSearchView', function() { + it('should match partial numbers', function() { + var $el = $('
'); + var view = new Whisper.ConversationSearchView({el: $el, input: $('')}).render(); + var maybe_numbers = [ + "+1 415", + "+1415", + "+1415", + "415", + "(415)", + " (415", + "(415) 123 4567", + "+1 (415) 123 4567", + " +1 (415) 123 4567", + "1 (415) 123 4567", + "1 415-123-4567", + "415-123-4567" + ]; + maybe_numbers.forEach(function(n) { + assert.ok(view.maybeNumber(n), n); + }); + }); + +});