Red Bridge Internet is a San Francisco WordPress Consulting firm specializing in WordPress websites and WordPress Plugin Development. We're the ones you have been searching for.

PHP ctype_alnum to Check Alpha Numeric Characters

A function of PHP’s; ctype_alnum can be used to test a string for alpha numeric characters. It will count a space as non-alphanumeric (which is right), so you can use it like so:

$string = “test !ng”;
if ( !ctype_alnum(preg_replace(‘/[[:space:]]/’, ”, $string)) )
echo “stringy baddy”

That’s about it. Funny thing is that it takes a few Google searches for matching alpha numeric characters with php to dig this up. I wanted something prettier than regex and since I always seem to forget it, up on the blog it goes!

Incoming search terms:

  • php ctype_alnum
  • ctype_alnum
  • ctype_alnum spaces
  • php ctype_alnum space
  • ctype_alnum php
  • CTYPE_alnum space
  • ctype_alnum with space
  • ctype_alnum and spaces
  • php check alphanumeric
  • count alphanumeric characters php

Related posts:

  1. How to Check MySQL Version on Command Line

One response to “PHP ctype_alnum to Check Alpha Numeric Characters”

  1. Rajeev Jha

    You should use a str_replace instead of preg_replace

Leave a Reply