Jump to content

[SOLVED] "nick" to be a simple letters


web_master

Recommended Posts

what you need is a regular expression combine with a preg function

 

if you want to make the user reenter the name until it contains only "simple letters" use

preg_match('/^[a-zA-Z]+$/i', $variable_contains_user_input)

combined with an if() statement, like

if(!preg_match('/^[a-zA-Z]+$/i', $variable_contains_user_input)){

    redisplay form and tell the user what is wrong

}

 

that is what I do

for letters only

 

<?php

if ( ctype_alpha($_POST['username']) )
{
// user has a name containing letters only
}

?>

 

and for letters and numbers

 

<?php

if ( ctype_alnum($_POST['username']) )
{
// user has a name containing letters and numbers only
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.