How to validate a variable is phone number in Php?
In this post, This function checks whether a variable is phone number or not.
1. Code:
<?php function checkIsPhoneNumber($var){ return preg_match('/^[0-9\(\)\-\[\]\.\+\s]+$/', $var); } var_dump(checkIsPhoneNumber("0988888887")); echo "<br>"; var_dump(checkIsPhoneNumber("soltuts.com")); ?>
2. Example:
Input:
Input: "0988888887" Input: "soltuts.com"
Output:
Output: true Output: false