// This is valid, both opening ( and closing ) var_dump(preg_match('~Valid(Regular)Expression~', null) === false); // This is invalid, no opening ( for the closing ) var_dump(preg_match('~InvalidRegular)Expression~', null) === false);
As the pozs user said , also consider placing @ before preg_match () ( @preg_match() ) in a test environment to prevent warnings or notifications.
To verify that RegExp runs it only with null (you don't need to know the data you want to test against upfront). If it returns an explicit false ( === false ), it is aborted. Otherwise, it is valid, although it does not need anything.
Therefore, there is no need to write your own RegExp validator. Wasting time ...
CodeAngry Oct 17 '12 at 18:44 2012-10-17 18:44
source share