The string should begin with \"S2\" followed by any 4 digits.
A matching string is \"S20165\".
I\'m trying with the following code, but it always echos OK ev
You have to use anchors:
/^S2[0-9]{4}$/
^ matches the start of the string and $ matches the end of the string, so this will make sure that you check the complete string and not just a substring.
You can also use \d instead of [0-9]. In PHP, as long as you do not use the 'u' pattern modifier, preg* functions are not Unicode aware, so the two are equivalent.