php - what is the best way to check if string consist of alphanumeric characters only? -
php - what is the best way to check if string consist of alphanumeric characters only? -
possible duplicate: php function determine if string consist of alphanumerical characters?
i need validate string using php , regexpresisons
string can min. 4 chars, 64 , needs aplphanumeric
all got far:
/^[a-za-z0-9]{4,64}$/
your regex right (assuming want match ascii alphanumerics), you're using incorrectly. check whether string $subject
matches regex, use
if (preg_match('/^[a-z0-9]{4,64}$/i', $subject)) { # successful match } else { # match effort failed }
note /i
alternative create regex case-insensitive. if want match other letters/digits, utilize /^[\p{l}\p{n}]{4,64}$/
regex.
php regex
Comments
Post a Comment