Alphanumeric validation in php


In this script string must contain  alphabet and number with at least 8 character and not accept any special character otherwise string is not valid
if (preg_match(‘/^\S*(?=\S{8,})(?=\S*[a-zA-Z])(?=\S*[\d])\S*$/’, $string))
{
echo ‘true’;
}
else
{
echo ‘false’;
}

************************************

In this script string contain alphabet or number and not accept any special character other wise string is not valid
if (preg_match(‘/^[a-z0-9A-Z]*$/’, $string))
{
echo ‘true’;
}
else
{
echo ‘false’;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s