Jump to content

A little validation help please.


phpretard

Recommended Posts

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

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";
}

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.