I am trying to display error messages to user if they entered a wrong uk phone number format or not a number, but the error messages not working.
HTML
<input type="text" name="phone" class="form-control" value="<?php echo $phone;?>" placeholder="Mobile Number ">
<span class="error"><?php echo $phoneErr;?></span>
PHP
$phoneErr = "";
$phone = "";
if (empty($_POST["phone"])) {
$phone = "";
} else if(!preg_match( $phone, '/^(?:\(\+?44\)\s?|\+?44 ?)?(?:0|\(0\))?\s?(?:(?:1\d{3}|7[1-9]\d{2}|20\s?[78])\s?\d\s?\d{2}[ -]?\d{3}|2\d{2}\s?\d{3}[ -]?\d{4}) $/'))
{
$phoneErr = "Invalid phone number";
}else {
$phone = test_input($_POST["phone"]);
}
test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
If it's not a number nothing will be inserted to the database, but if I typed a number 9223372036854775807 will be inserted, this value is not the one I entered. I have done some researches, I think this value means invalid string.
Other parts of my form are working fine only the phone number not working well, I am not sure why.