Skip to content

Instantly share code, notes, and snippets.

@rujealfon
Forked from cferdinandi/has-characters.php
Created April 25, 2018 03:58
Show Gist options
  • Select an option

  • Save rujealfon/1b03fd1ac0a7508179c3c63c0899a55f to your computer and use it in GitHub Desktop.

Select an option

Save rujealfon/1b03fd1ac0a7508179c3c63c0899a55f to your computer and use it in GitHub Desktop.
Test strings for letters, numbers, and special characters. Returns true if they exist, false if they don't. Forked from http://stackoverflow.com/a/9588010/1293256
<?php
// Does string contain letters?
function _s_has_letters( $string ) {
return preg_match( '/[a-zA-Z]/', $string );
}
// Does string contain numbers?
function _s_has_numbers( $string ) {
return preg_match( '/\d/', $string );
}
// Does string contain special characters?
function _s_has_special_chars( $string ) {
return preg_match('/[^a-zA-Z\d]/', $string);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment