1660645609
In today’s world, assuring real sign-ups is critical for your business. Without genuine registrations, your marketing campaign will fail miserably. Email address validation is a popular way of verifying real sign-ups. But phone number validation works as an extra layer of security. It helps you to prevent fraudulent activities effectively. In this post, you will find a simple way of validating phone numbers using PHP code.
The easiest way to create a PHP validate phone number function is using inbuilt PHP filters.
However, developers around the world are preferring to use regular expressions. PHP provides powerful functions for parsing regular expressions. So, you can validate phone number with different types of formats effectively.
To validate phone number using regular expression, you have to follow these steps: Validate Phone Number in PHP
Create a PHP validate phone number function, called validating(), with a parameter of $phone.
function validating($phone){
Then you have to create an if/else statement for determining whether the given phone number is valid or not. Let’s say that the genuine phone number is 10 digits long, ranging from 0 to 9. To perform the validation, you have to utilize this regular expression: /^[0-9]{10}+$/. Also, you have to use the reg_match() function.
if(preg_match('/^[0-9]{10}+$/', $phone)) {
echo "Valid Phone Number";
} else {
echo "Invalid Phone Number";
}
If the given telephone number matches the specified regular expression, it will print “Valid Phone Number.” Otherwise, it will print “Invalid Phone Number” as the error message.
Now, let’s try verifying different phone numbers by calling our validating() function for number validation in PHP:
validating("1016660180"); //10 digits valid phone number
validating("101666018000"); //12 digits invalid phone number
validating("101$666*01"); //10 letters phone number with invalid characters
validating("101$666*0180"); //10 digits phone numbers with invalid characters
4. You will see this output:
Valid Phone Number
Invalid Phone Number
Invalid Phone Number
Invalid Phone Number
Overall, the following code will look like this:
function validating($phone){
if(preg_match('/^[0-9]{10}+$/', $phone)) {
echo " Valid Phone Number";
} else {
echo " Invalid Phone Number";
}
}
validating("1016660180"); //10 digits valid phone number
validating("101666018000"); //12 digits invalid phone number
validating("101$666*01"); //10 letters phone number with invalid characters
validating("101$666*0180"); //10 digits phone numbers with invalid characters
That’s it! You have learned the way of validating phone numbers in PHP using regular expressions. The same rules apply to mobile number validation.
Phone numbers have different formats. So, verifying them could have been really challenging. Fortunately, using a PHP function has made the process very simple.
As said earlier, the in-built PHP filter can make it easier for you to validate phone number. Here, you will use it to validate numbers with different formats.
1. First, you have to create a function, called validating().
function validating($phone){
2. Create a variable, called valid_number. It will have the filter_var() function with a FILTER_SANITIZE_NUMBER_INT constant.
$valid_number = filter_var($phone, FILTER_SANITIZE_NUMBER_INT);
3. Now, you can print the valid_number variable.
echo $valid_number.;
}
4. Finally, let’s call the validating() PHP function with for mobile number validation.
validating("101-666-0260");
You will see this output: 101-666-0260
Overall, the code will look like this:
function validating($phone){
$valid_number = filter_var($phone, FILTER_SANITIZE_NUMBER_INT);
echo $valid_number.;
}
validating("101-666-0260");
That’s how you validate a cell phone number with the in-built PHP filter.
A phone number can have certain characters, like + and -. But what will happen if the user enters the number incorrectly with special characters, like $ and *? You need to find a way to filter them out.
By using filter_var() function, you can strip them off from the given phone number.
Let’s try validate a phone number that contains $ and *, like this: 101$777*0280
Let’s use this code:
function validating($phone){
$valid_number = filter_var($phone, FILTER_SANITIZE_NUMBER_INT);
echo $valid_number.;
}
validating("101$777*0280");
You will see an output with $ and * being removed from the given phone number: 1017770280
International phone numbers start with + with some also needing the area code. So, you need to figure out a way to prevent it from being filtered out. Fortunately, filter_var() function supports the + sign. So, you will never have to worry about it being stripped off.
Let’s try performing something for international users, for example an Indian phone number validation. The number looks like this: +91-202-5555-0234
As you can see, the country code of India is +91. How will filter_var() function react if an Indian phone number is entered? Will it filter out the + sign?
Let’s use this code to figure out what happens:
function validating($phone){
$valid_number = filter_var($phone, FILTER_SANITIZE_NUMBER_INT);
echo $valid_number.;
}
validating("+91-202-5555-0234");
You will see an output like this: +91-202-5555-0234
As you can see, the filter_var() function supports the + sign. So, it’s not being filtered out.
By using APIs, you can validate phone numbers effortlessly. They come with all the necessary functions for verification. You just need to enter the number. The API will handle the rest. You don’t have to write any code from scratch. So, you can validate the phone numbers effortlessly.
You can try using Abstract’s phone number validation and verification API. It is reliable, blazing-fast, and easy to maintain. It can help you to validate phone numbers effortlessly.
Let’s use Abstract’s Phone Number Validation and Verification API to validate this phone number: 14154582468.
https://phonevalidation.abstractapi.com/v1/
? api_key = YOUR_UNIQUE_API_KEY
& number = 14154582468
If the phone number request is successful, you will see this output:
{
"number": "14154582468",
"is_valid_number": true,
"local_format":"4154582468",
"international_format": "+14154582468",
"country_name": "United States of America",
"country_code": "US",
"country_prefix":"+1",
"registered_location": "San Francisco, CA",
"carrier":"Verizon USA",
"line_type": "Mobile",
}
The given phone number is valid, as the "is_valid_number" field is set to “true.” Also, it provides you with a variety of geolocation data, including country name and registered location of the phone number. You can utilize this information to enhance your marketing strategy.
https://www.pakainfo.com/how-to-validate-phone-numbers-with-php/
As you can see, you don’t have to write any code from scratch. There is no need to utilize regular expressions or PHP in-built functions. You just need to get the API key and enter the phone number that you want to verify. Abstract’s Phone Number Validation and Verification API will handle the rest.
1594769515
Data validation and sanitization is a very important thing from security point of view for a web application. We can not rely on user’s input. In this article i will let you know how to validate mobile phone number in laravel with some examples.
if we take some user’s information in our application, so usually we take phone number too. And if validation on the mobile number field is not done, a user can put anything in the mobile number field and without genuine phone number, this data would be useless.
Since we know that mobile number can not be an alpha numeric or any alphabates aand also it should be 10 digit number. So here in this examples we will add 10 digit number validation in laravel application.
We will aalso see the uses of regex in the validation of mobile number. So let’s do it with two different way in two examples.
In this first example we will write phone number validation in HomeController where we will processs user’s data.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class HomeController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('createUser');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'phone' => 'required|digits:10',
'email' => 'required|email|unique:users'
]);
$input = $request->all();
$user = User::create($input);
return back()->with('success', 'User created successfully.');
}
}
In this second example, we will use regex for user’s mobile phone number validation before storing user data in our database. Here, we will write the validation in Homecontroller like below.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use Validator;
class HomeController extends Controller
{
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('createUser');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'phone' => 'required|regex:/^([0-9\s\-\+\(\)]*)$/|min:10',
'email' => 'required|email|unique:users'
]);
$input = $request->all();
$user = User::create($input);
return back()->with('success', 'User created successfully.');
}
}
#laravel #laravel phone number validation #laravel phone validation #laravel validation example #mobile phone validation in laravel #phone validation with regex #validate mobile in laravel
1616903742
Simple contact form submits in PHP MySQL with jQuery validation. In this tutorial, you will learn how to create a contact form in PHP, and how to submit form data into the MySQL database with jQuery validation.
This tutorial helps you step by step for creating or submit a contact forms in PHP MySQL DB with jQuery validation. And you can use this form for your business queries. The good thing is you can use this contact form in your web application too.
Just follow the few below steps and easily create and submit contacct form in PHP MySQL with jquery validation.
https://www.tutsmake.com/php-contact-form-with-jquery-validation-example/
#jquery validation in php registration form #simple jquery form validation example in php #jquery validation in php form
1598427973
complete login system php mysql. Here, i will show you how to build complete login system in php mysql using session.
And as well as how to create login page, user profile page in php with database and validation.
https://www.tutsmake.com/login-system-in-php-mysql-source-code-with-validation/
#login system php source code #simple login page in php with database source code #login page in php with database and validation #simple login form in php with mysql database #php login session
1597820991
Looking to develop a PHP based website from scratch or revamp your existing website?
HourlyDeveloper.io has always been an industry leader for companies and business owners looking to hire PHP web developer. By choosing to Hire PHP Developer from our company, you can always expect the best results. Our PHP services and solutions are always flexible which means that no matter the nature of your project, you can always count on us for getting the best PHP expertise.
Consult with our experts: https://bit.ly/3aEGxPy
#hire php developer #php developer #php development company #php development services #php development #php
1617276472
A framework that can drastically cut down the requirement to write original code to develop the web apps as per your requirement is PHP Framework. PHP frameworks offer code libraries for commonly used functions to reduce the development time.
Want to use PHP Web Frameworks for your web applications?
WebClues Infotech offers a service to hire dedicated PHP developers for all of the below-mentioned frameworks
Not sure which framework to use for your PHP web application?
Schedule Interview with PHP Developer https://bit.ly/3dsTWf0
Email: sales@webcluesinfotech.com
#hire php developer #hire php web developers #hire php developer in 2021 #hire php developers & dedicated php programmers #hire php developers india #hire and outsource freelance php developers