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 return
s 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
Similar Kata:
Stats:
Created | Mar 25, 2016 |
Published | Mar 25, 2016 |
Warriors Trained | 2355 |
Total Skips | 139 |
Total Code Submissions | 5511 |
Total Times Completed | 1311 |
JavaScript Completions | 569 |
Ruby Completions | 121 |
Python Completions | 638 |
Total Stars | 38 |
% of votes with a positive feedback rating | 88% of 281 |
Total "Very Satisfied" Votes | 223 |
Total "Somewhat Satisfied" Votes | 47 |
Total "Not Satisfied" Votes | 11 |