I was wondering what the most concise way to see if this string is not null or not 8 characters long or not numbers do this I am just not sure how to put all of those conditions together
that seems to be the talk of the day these days..... would that also check for spaces for instance i was gonna use strlen to check for how many characters say it was an 8 number string 12345678 if i use strlen then they could still enter 12345 78 and it would pass
strlen() returns the length of the string. A space is counted as character, so 12345 78 would be an 8 character long string.
With the right pattern, it won't. I didn't test my code above my I'm pretty confident that it works like it's supposed to.
nico_swd's regular expression answer fits your requirement of "most concise" in the original post. If you are looking for a non regular expression answer you can convert the string to an integer and then if it is less than 10000000 or more than 99999999 it is invalid. Otherwise, valid. <?PHP $string = '12345678'; $number = intval($string); echo "$string => $number => "; if ($number < 10000000 || $number > 99999999) { echo 'invalid'; } else { echo 'valid'; } ?> PHP: