php & preg_match function for alpha-numeric only with string size LIMITATION all in one?

Fagush

New member
Hello. Does anybody know how to limit the size of strings using preg_match function?
I need to accept only string consists of a-zA-z0-9 with length LESS THAN 51 symbols (= less or equal 50), empty string is OK.
Thank you.
 
By using the {x,y} operator in a regular expression, the last thing before it should be repeated any number of times that is in the range of "x to y".

For example, to do what you said, this would be used:
preg_match('/^[a-zA-Z0-9]{0,50}$/', $string);
 
Back
Top