diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 7d96d0b2..19c3c0a8 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -82,3 +82,8 @@ Programming Language: Java, C, HTML, CSS, Kotlin Email: josephlee050@gmail.com +Name: [John Braun](https://github.com/jhnbrn90) +About: I am doing a PhD in organic chemistry and really like programming. Used Laravel to create some useful tools for our research group, amongst others a chemicals inventory, booking system and supporting information manager. +Programming Language: PHP, JavaScript +Email: jbraunnl@gmail.com + diff --git a/telephone-validator/validator.php b/telephone-validator/validator.php new file mode 100644 index 00000000..75dcc85e --- /dev/null +++ b/telephone-validator/validator.php @@ -0,0 +1,44 @@ +phoneNumber = $phoneNumber; + } + + /** + * Validate the passed in phone number + * using the defined regex + * @return bool + */ + public function validate() + { + preg_match($this->regex, $this->phoneNumber, $matches); + return !empty($matches); + } +} + +// Register a new phone number +$phoneNumber = new PhoneNumber('2-123-123-1231'); + +// validate the phone number, returning a boolean +$phoneNumber->validate(); + +// return a statement (string) based on the boolean value +echo $phoneNumber->validate() ? 'Valid phone number :-)' : 'Invalid phone number :-('; +