Jump to content

preg_match


rbrown

Recommended Posts

I'm trying to us a preg_match where if the string contains

spaces, dashes, underscores, A-z, a-z, 0-9 it will let it pass.

If it has any other character it won't.

 

I got the it to work with the underscore, A-z, a-z, 0-9 but trying to add the dash and space I'm just not getting it right.

And I'm running out of hair... ;)

 

example file names:

GittlingerBaier_AnnMarie_19707_04_06_11.pdf --- this works

Gittlinger-Baier_Ann Marie_19707_04_06_11.pdf --- want this to pass

Gittlinger,Baier_Ann%Marie_19707_04_06_11.pdf --- want this to fail

 

This below works. But it doesn't allow spaces or dashes

$file_name_exploded_extension = explode('.',$file['name']); 

if (preg_match("/^[a-z0-9_]+$/i", $file_name_exploded_extension['0']) ) { 

 

Thanks,

Bob

Link to comment
https://forums.phpfreaks.com/topic/234929-preg_match/
Share on other sites

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.