Last active
January 7, 2024 11:58
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
?> |
Great and simple example - Thank You!
THX
Matur Nuhun Bosku...
and test string for a brace ( i.e, { ) ?
test for brace ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CTRL-C