Showing posts with label Regex. Show all posts
Showing posts with label Regex. Show all posts

Wednesday, 7 September 2016

Email Address Validation in PHP using Regex

Simple regex to validate email address in php. Validate email address in php regex while submitting form.

$email_regex = "/([a-z0-9_]+|[a-z0-9_]+\.[a-z0-9_]+)@(([a-z0-9]|[a-z0-9]+\.[a-z0-9]+)+\.([a-z]{2,4}))/i";
if(!preg_match($email_regex, $email)) {
    echo "Invalid Email Address";
}
else {
    echo "Valid Email Address";
}

Friday, 12 August 2016

PHP Function to Check Prime Number

Check if a given number is a prime number or not using this simple PHP script.
Make use of this simple php function to find whether the number is a prime number or not.

function checkPrimeNumber($number) {
    $string = str_repeat("1", $number);
    if(preg_match( '/^1?$|^(11+?)\1+$/', $string )==0) {
        return true;
    }
    return false;
}