How would I use regular expressions to see in a field has been filed with only character a-z, A-Z, or 0-9?
The length does not matter!!
How would I use regular expressions to see in a field has been filed with only character a-z, A-Z, or 0-9?
The length does not matter!!
if (preg_match('/^[a-zA-Z0-9]+$/', $string)) {
// Do something
}
^ and $ match against the beginning and end of the string, to ensure it only matches if the entire string is valid. [ and ] denote a set of characters, any of which can be matched. + tells it to match one or more of the set, so that it won't accept an empty string, but will accept a string of any length made up of those characters. You can replace + with * (which matches 0 or more characters) in order to allow empty strings to match.
A regex tutorial and testing tool, for further reading. And of course there's always the manual.
Originally posted by fnbcprog
How would I use regular expressions to see in a field has been filed with only character a-z, A-Z, or 0-9?
The length does not matter!!
You'll want to check out the preg_match() function.
If you need help with the regex itself, check out http://www.troubleshooters.com/codecorn/littperl/perlreg.htm