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

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -