Jump to content

Recommended Posts

ctype_alnum by itself only checks that it is an alphanumeric string.  It does not determine whether it has at least one number in it.

 

if (preg_match('~^[a-z0-9]*[0-9][a-z0-9]*$~i',$subject)) {
  // $subject is alphanumeric and contains at least 1 number
} else {
  // failed
}

 

OP: This code will do what you want with one caveat: Technically a string consisting of a single digit like "9" will pass.  If you want to do other things like enforce a minimum/maximum length, be more specific.

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.