reddensoft
Banned-Spam
- Oct 7, 2022
- 84
- 9
Can anyone help me how to add validation in phone number and email id using PHP while creating a website.
I can help you.Can anyone help me how to add validation in phone number and email id using PHP while creating a website.
<?php
$email = $_POST['email']; // Assuming the email is being sent via a POST request
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Valid email address.";
} else {
echo "Invalid email address.";
}
?>
<?php
$phone = $_POST['phone']; // Assuming the phone number is being sent via a POST request
// Basic validation for a 10-digit phone number (common in the US, but adjust regex for other countries)
if (preg_match('/^[0-9]{10}$/', $phone)) {
echo "Valid phone number.";
} else {
echo "Invalid phone number.";
}
?>
You can use PHP’s filter_var() function to validate email and a regular expression (preg_match()) to validate phone numbers.Can anyone help me how to add validation in phone number and email id using PHP while creating a website.