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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.