16.1 . PHP Practical - Validate Input Data Using Regular Expression
16.1 . PHP Practical - Validate Input Data Using Regular Expression
?>
Validate Number
The below code validates
that the field will only
contain a numeric
value. For example
- Mobile no. If the Mobile
no field does not receive
numeric data from the user,
<?php
if (!preg_match ("/^[0-9]{10}$/", $mobileno) ){
$ErrMsg = "Only 10 numeric values allowed.";
{
$ErrMsg = "Only numeric value is allowed.";
echo $ErrMsg;
}
else
{
echo $mobileno;
}
?>
Validate Email
• A valid email must contain @ and .
symbols. PHP provides various
methods to validate the email
address. Here, we will use regular
expressions to validate the email
address.