7 kyu

Valid HK Phone Number

569 of 1,311donaldsebleung

Description:

Valid HK Phone Number

Overview

In Hong Kong, a valid phone number has the format xxxx xxxx where x is a decimal digit (0-9). For example:

"1234 5678" 
// is valid

"2359 1478" 
// is valid

"85748475" 
// invalid, as there are no spaces separating the first 4 and last 4 digits

"3857  4756" 
// invalid; there should be exactly 1 whitespace separating the first 4 and last 4 digits respectively

"sklfjsdklfjsf" 
// clearly invalid

"     1234 5678   " 
// is NOT a valid phone number but CONTAINS a valid phone number

"skldfjs287389274329dklfj84239029043820942904823480924293042904820482409209438dslfdjs9345 8234sdklfjsdkfjskl28394723987jsfss2343242kldjf23423423SDLKFJSLKsdklf" 
// also contains a valid HK phone number (9345 8234)

Task

Define two functions that returns whether a given string is a valid HK phone number and contains a valid HK phone number respectively (i.e. true/false values).

If in doubt please refer to the example tests.

Regular Expressions
Fundamentals

Stats:

CreatedMar 25, 2016
PublishedMar 25, 2016
Warriors Trained2355
Total Skips139
Total Code Submissions5511
Total Times Completed1311
JavaScript Completions569
Ruby Completions121
Python Completions638
Total Stars38
% of votes with a positive feedback rating88% of 281
Total "Very Satisfied" Votes223
Total "Somewhat Satisfied" Votes47
Total "Not Satisfied" Votes11
Ad
Contributors
  • donaldsebleung Avatar
  • jhoffner Avatar
  • GiacomoSorbi Avatar
  • Voile Avatar
  • FArekkusu Avatar
  • hobovsky Avatar
  • Just4FunCoder Avatar
Ad