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? Quote Link to comment 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"; } Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 5, 2009 Share Posted April 5, 2009 \s <<< means space . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.