I would like to ask a question about preg_match and how the information about the "date" is actually determined to be in compliance with the regular expression, or not in compliance with the regex. Even after months of doing PHP and regex, I am just not clear on this issue. My question is, are the two regular expressions below equivalent? Notice that the first is a PREG_MATCH, while the second is a NOT PREG_MATCH. When a user mistakenly enters a date like 10-10-2014 which is in the wrong format, is the data actually sent to the server and THEN rejected by the server as being non-compliant with the regex, OR is the data stopped from being sent to the server in the first place? What I'm trying to understand is, does $date = $_POST['date'] refer to the act of the browser SENDING user data TO the server, OR does it refer to the act of the browser FETCHING user data FROM the server? In the first alternative below, does the server even "see" the wrongly-formatted date, or does the browser STOP the wrongly-formatted date from being sent to the server in the first place? Are the two things below exactly equivalent?
Alternative number 1:
if (preg_match("/^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$/, "$date"){
$date = $_POST['date'];
}
Alternative number 2:
if (!preg_match("/^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$/, "$date"){
$date = "";
$dateErr = "Invalid email format";
}