How many times have we written the regular expressions to check whether it only consists of alphabets or just numeric?
And how many time we were so sure about that expression will work exactly?
Wished, it was known to me before doing a lots of those stupid regular expression stuffs.
So, PHP has a set of ctype_ prefixed functions. And now we can stop doing those dirty regular expression stuffs we do with regular expression.
The functions provided by ctype extension check whether a character or string falls into a certain character class according to the current locale.
It is not much, but it would actually remove a lots of common issues we face.
- ctype_alnum — Check for alphanumeric character(s)
- ctype_alpha — Check for alphabetic character(s)
- ctype_cntrl — Check for control character(s)
- ctype_digit — Check for numeric character(s)
- ctype_graph — Check for any printable character(s) except space
- ctype_lower — Check for lowercase character(s)
- ctype_print — Check for printable character(s)
- ctype_punct — Check for any printable character which is not whitespace or an alphanumeric character
- ctype_space — Check for whitespace character(s)
- ctype_upper — Check for uppercase character(s)
- ctype_xdigit — Check for character(s) representing a hexadecimal digit
Everything is awesome.