Jump to content

Fixing my statment


adam84

Recommended Posts

@sasa:

 

sure, checking for presence of characters NOT acceptable is an alternate way to go.  However, it looks like you just c/p'd his base pattern, which doesn't match what he actually says he wants to match for.  He says hyphens are acceptable, and he did not mention single quotes.

 

@adam84:

 

FYI neither of these addresses a couple of issues that are commonly addressed with. 

 

- These regexes do not account for length limits.  Most sites want a name to have a minimum amount of characters, or at least limit the maximum.

- These regexes do not prevent values like "---------" or "              " or "- - - - - -" or ".....---.--  ---" or...you get the picture.

Link to comment
https://forums.phpfreaks.com/topic/245816-fixing-my-statment/#findComment-1262604
Share on other sites

Based strictly on the OP question, you could also do it without using a pattern at all.

 

function checkName($name) {
if( ctype_alpha( str_replace(array('-', ' ', '.'), '', $name)) ) {
	return TRUE;
} else {
	return FALSE;
}
}

Link to comment
https://forums.phpfreaks.com/topic/245816-fixing-my-statment/#findComment-1262608
Share on other sites

Just an FYI. If you need a function that is supposed to return a Boolean then it is not necessary to do something such as

if($foo==$bar)
{
    return true;
}
else
{
    return false;
}

 

Just return the comparison. Using Pikachu's solution as an example:

function checkName($name) 
{
    return (ctype_alpha( str_replace(array('-', ' ', '.'), '', $name)) );
}

 

Link to comment
https://forums.phpfreaks.com/topic/245816-fixing-my-statment/#findComment-1262921
Share on other sites

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.