rendered paste body<?php$_POST['firstr'] = 'Fred';$_POST['lastr'] = 'Bloggs';//uncomment below to test$_POST['midr'] = 'bill';$valid = true;if(empty($_POST['firstr']) || empty($_POST['lastr'])){ $valid = false;}else{ $firstr = trim($_POST['firstr']); $lastr = trim($_POST['lastr']); if(!ctype_alpha($firstr) || !ctype_alpha($lastr)) { $valid = false; } else { if(ctype_lower($firstr)) $firstr = ucfirst($firstr); if(ctype_lower($lastr)) $lastr = ucfirst($lastr); if(!preg_match('@^[A-Z][a-z]+$@', $firstr)) $valid = false; if(!preg_match('@^[A-Z][a-z]+$@', $lastr)) $valid = false; if(!empty($_POST['midr'])) { $midr = trim($_POST['midr']); if(!ctype_alpha($midr)) { $valid = false; } else { if(ctype_lower($midr)) $midr = ucfirst($midr); if(!preg_match('@^[A-Z][a-z]+$@', $midr)) $valid = false; } } if(!empty($midr)) { $fullname = $firstr.'_'.$midr.'_'.$lastr; } else { $fullname = $firstr.'_'.$lastr; } } }if($valid){ echo $fullname;}else{ echo 'INVALID';}?>