JQuery Validation for MMMYY using regex

Here is a JQuery validation for MMMYY format. The month name are case sensitive. Enjoy.
<script type="text/javascript">
$().ready(function () {
 
  $.validator.addMethod("mmmyy", function (value, element) {
    return this.optional(element) || /^(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(d{2})$/.test(value);
  }, "This field must contain month and year in MMMYY format.");
 
  $("#formname").validate({
    rules: {
      textboxid: {
        required: true,
        mmmyy: true
      }
    },
 
    messages: {
      textboxid: {
        required: "This field is required."
        //Use default error from the method. If you would like to override the error you can add mmmyy: "custom error message" here
      }
    }
  });
});
</script>
 
<input id="textboxid" name="textboxid" type="text" />
FacebookTwitterGoogle+Share

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA Image

*