Skip to content

Instantly share code, notes, and snippets.

@cferdinandi
Last active January 7, 2024 11:58
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save cferdinandi/6688744 to your computer and use it in GitHub Desktop.
Save cferdinandi/6688744 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);
}
?>
@FranyePodolski
Copy link

Thanks a lot!

Copy link

ghost commented Jul 15, 2018

This is great!

@ertanuj96
Copy link

Does there is a way to match each character of "string" against some predefined characters when the "string" is encrpyted which we have to match with the set of predefined characters?

@sin5678
Copy link

sin5678 commented Oct 29, 2018

CTRL-C

@AleksandarSavic95
Copy link

Great and simple example - Thank You!

@acki
Copy link

acki commented Mar 22, 2020

THX

@aacassandra
Copy link

Matur Nuhun Bosku...

@wordpressyu
Copy link

and test string for a brace ( i.e, { ) ?

@wordpressyu
Copy link

test for brace ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment