Reputation: 2192
I am using javascript regex for validating user entered date in format mm/yyyy. I have made regex for this and its working fine, but when I enter ab/abcd its still validating it.
This is my JS and HTML code
function validate() {
var name = document.getElementById("name").value;
var pattern = /\d|\/|\d{4}/;
if (pattern.test(name)) {
alert(name +" has alphanumeric value");
return true;
} else {
alert("Name is not valid.Please input alphanumeric value!");
return false;
}
}
Date: <input type="text" name="name" id="name" />
<input type="submit" value="Check" onclick="validate();"/>
How can I validate the entered date in mm/yyy format, I am using Jquery DatePicker which allows to select date in this format, and the datepicker also allows manual input. like this Date Picker Is there any alternate suggestion for this?
Upvotes: 0
Views: 39