jquery failing when element doesn't exist

I am using the following script to customize some jquery validation on some forms. This script is called once and is used by a template file to generate one of a few different forms, meaning the script is called for all forms.

The top part (//Make sure there is a title) works fine on all forms if it's used alone, because all form have that title element, but the two other validations (expiration and start/end date) only apply to one of the forms, otherwise those fields don't exist.

I'm getting the error "(index):1966 Uncaught TypeError: Cannot read property 'replace' of undefined" when trying to submit a form that does not have these elements, even though I added conditionals to check for those elements first. Also, the validation jquery is failing to show when this happens.