Showing posts with label Regular expression. Show all posts
Showing posts with label Regular expression. Show all posts

Thursday, January 20, 2011

Email address validation in PHP using REGEX

Code to validate:

if (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$',$_REQUEST['email'])) { 
    echo 'Valid'; 
       } else { 
    echo 'Invalid'; 
       }

Regular Expression Samples

Regx Expression for removing repeated words (case insensitive)

$text = preg_replace("/\s(\w+\s)\1/i", "$1", $text);

Output : ‘Keep your your head’ becomes ‘Keep your head’

Password complexity

Tests if the input consists of 6 or more letters, digits, underscores and hyphens.
The input must contain at least one upper case letter, one lower case letter and one digit.

'\A(?=[-_a-zA-Z0-9]*?[A-Z])(?=[-_a-zA-Z0-9]*?[a-z])(?=[-_a-zA-Z0-9]*?[0-9])[-_a-zA-Z0-9]{6,}\z'

Customizing the Search form - Drupal

To change the label text and text inside the search box and the text on the submit and changing the Submit button image, you can use the fo...