jayant kumar jayant kumar - 3 months ago 5
PHP Question

php code to validate alphanumeric string

I want to validate alphanumeric string in form text box in php. It can contain numbers and special characters like '.' and '-' but the string should not contain only numbers and special characters. Please help with the code.

Answer

Try this

if(preg_match('/^[a-zA-Z]+[a-zA-Z0-9._]+$/', input))
{
    //Valid
}
else
{
    //invalid
}
Comments