JavaScript Form Validation - Date
It may be tempting to validate date input using regular expressions. However, the better alternative will be to actually convert the date to a date object and test it. For example, a simple regular expression test would approve this date: 2011/02/29 perfectly valid but there is no such date (since 2011 was not a leap year) Validate dates in the format: MM/DD/YYYY (or MM-DD-YYYY or MM.DD.YYYY ) function validateDate_MMDDYYYY(input_date) { var parts = input_date.
JavaScript Form Validation - Phone Numbers
The easiest way to validate phone numbers using Javascript would be to use Regular expressions. However there are different formats of Phone numbers depending on the user’s preference. Here are some regular expressions to validate phone numbers Phone number validation using a simple Regular expression function validatePhoneNumber(input_str) { var re = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im; return re.test(input_str); } This function will allow phone numbers entered in the formats like this (123) 456-7890 (123)456-7890 123-456-7890 1234567890 Try the working demo See the Pen eYmbjpG by Prasanth (@prasanthmj) on CodePen.