Fixed bug when invalid dates are entered.

Changed two things.
1) Turned trim into one function call for the date.
Used `.replace(/^\s*|\s*$/g, "")` instead of `.replace(/^\s*/, "").replace(/\s*$/, "")`
2) Fixed bug that returned NaN for invalid date values.
To view this bug, open up the demo page and enter "abc" inside the input text box.
Hit the enter key and then click on the input text box. "undefined NaN" should be displayed.