phpretard Posted April 5, 2009 Share Posted April 5, 2009 I only want to allow letter and numbers and a space in between. If there is a space after then I need to strip that but, that might be another issue. <?php $docName="Appraisal Agreement"; if (preg_match('/^[^a-z0-9-_ ]+$/i',$docName)){ echo "No Pass"; }else{echo "Passed";} ?> Any help today? Link to comment https://forums.phpfreaks.com/topic/152650-a-little-validation-help-please/ Share on other sites More sharing options...
ghostdog74 Posted April 5, 2009 Share Posted April 5, 2009 how about this, no regex $docName="Ap%praisal Agreement"; $a = explode(" ",$docName); if ( count($a) == 2){ print "ok, space in between\n"; } if ( ctype_alnum ($a[0]) ){ print "$a[0] is alphanumeric\n"; }else{ print "$a[0] is not alphanumeric\n"; } if ( ctype_alnum ($a[1]) ){ print "$a[1] is alphanumeric\n"; }else{ print "$a[1] is not alphanumeric\n"; } Link to comment https://forums.phpfreaks.com/topic/152650-a-little-validation-help-please/#findComment-801666 Share on other sites More sharing options...
redarrow Posted April 5, 2009 Share Posted April 5, 2009 \s <<< means space . Link to comment https://forums.phpfreaks.com/topic/152650-a-little-validation-help-please/#findComment-801671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.