I have a submit form with 4 fields to be populated by a client; "first_name" "last_name" "questions" "administrative_questions" None of the fields can allow number values to be submitted and must return an error if an attempt to post is made with numbers entered. The first two fields are required. The third and fourth field require that one or the other be populated, with no numbers and both can be populated as well but both cannot be blank.
With Ryans guidance, I have the following code in place to deal with the "questions" and "administrative_questions" fields, and it allows one or the other to be blank BUT if both are populated, one will allow numbers to pass through but not if BOTH have numbers or both have number AND text. Only if one has text and one has numbers or numbers and text mixed. The requirements for this form demand that no numbers be allowed to submit. It's a compliance issue with a finance advisory group. Clients can't be allowed to provide account numbers, bank balances or fiscal values of any kind through this web-based submission form and they MUST provide first and last name.
$error_message = "";
$string_exp = "/^[\n\r\A-Za-z .,?!'-]+$/";
$questionsEntered = preg_match($string_exp,$questions);
$string_exp = "/^[\n\r\A-Za-z .,?!'-]+$/";
$administrativeQuestionsEntered = preg_match($string_exp,$administrative_questions);
if ($questionsEntered && $administrativeQuestionsEntered) {
// both were entered - ok?
}
elseif ($questionsEntered || $administrativeQuestionsEntered) {
// either one was entered - ok
}
else {
// explain that at least one of them must be entered
$error_message = 'your error message';