You appear to be a bot. Output may be restricted
Description
Return a validated name fieldAt the start of coding this all we wanted to do was to not accept a name starting with a digit e.g. 532ff6123 Because, except for names in non Latin languages, it should really be a letter. So I looked at stack overflow and found this, which seems like as good a start as any http://stackoverflow.com/questions/888838/regular-expression-for-validating-names-and-surnames Trying this Regular expression ^[\p{L} \.'\-]+$ But in the 'complete tested solution' it's ^[\p{L}\p{M}' \.\-]+$ And perhaps we need to convert apostrophes to ' Apostrophes are dealt with by stripping slashes from the input value before performing the preg_match. Later, if the field is redisplayed, then we run stripslashes again.
Usage
$string|null = oiksp_validate_name();
Parameters
Returns
string|null the name field if validatedSource
File name: oik-squeeze/shortcodes/oik-squeeze.phpLines:
function oiksp_validate_name() { $name = bw_array_get( $_REQUEST, "oiksp_name", null ); $name = trim( $name ); $name_for_match = stripslashes( $name ); $matched = preg_match("/^[\p{L} \.'\-]+$/", $name_for_match, $output_array); //bw_trace2( $output_array, "output array for name:$name:" ); //bw_trace2( $matched, "matched", false ); if ( !$matched ) { $_REQUEST['oiksp_name'] = $name; $name = null; } /** * Don't process requests where the Name is more than 5 words. * This is just spam. * Note: The user doesn't get any message when the form is redisplayed. */ $words = explode( ' ', $name); if ( count( $words ) >= 5 ) { bw_trace2( $name, 'Name considered to be spam: ', false); $_REQUEST['oiksp_name'] = ''; $name = null; } return( $name ); }View on GitHub