Form Validation in PHP – Simplified

I was created a form earlier today, when I had to add Phone Number validation to the existing validation. This form already included email validation, but I decided to go over it as well.

Email Validation

This is a very similar validation, but there is nothing needed to customize:

function valid_email( $str )
{
    // This checks for "[email protected]"
    return ( ! preg_match("/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str)) ? FALSE : TRUE;
}

if( ! valid_email( $_POST['email_address'] ) {
    echo "Please enter a valid email address."
}

Phone Number Validation

Edit: Please check out my new post on phone number validation, as it has a much more efficient regular expression pattern.

Phone Number validation is fairly straight forward, but has one major issue – formatting! There are many ways of putting in a phone number, and for usability’s sake, it’s best to supp
Continue reading Form Validation in PHP – Simplified