Phonenumber Ethio$ Age$...

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

$phoneNumber = "+251911-223344";

preg_match('/((^(\+251|0)\d{3})-?\d{6})/');//Simple regex to validate ethiopian phone number

Validate Name
function validateName($name) {

if (preg_match("/^[a-zA-Z'. -]+$/", $name)) {

return true;

return false;

Validate Age
function validateAge($age) {

if (preg_match("/^[0-9]+$/", $age)) {

return true;

return false;

Validate Price
Allowing only 2 digits after dot. Price can be decimal or without
decimal. 9 and 9.99 = both are true.
function validatePrice($price) {

if (preg_match("/^[0-9]+(\.[0-9]{2})?$/", $price)) {

return true;

return false;
}

Validate Email
function validateEmail($email) {

if (preg_match("/^[_a-z0-9-+]+(\.[_a-z0-9-+]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})
$/", $email)) {

return true;

return false;

If you are using PHP 5.2 and above then you can


use filter_var function to validate name, age and email. This has
made validation a lot more easier task. We don’t need to write any
regular expression code while using filter_var function.
Validate Email
function validateEmail($email) {

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {

return true;

return false;

You might also like