Nida Nida - 1 year ago 122
Javascript Question

Jquery for masking of input for entering date correctly

I have used online jquery reference from in my project.

<script type="text/javascript">
var s = jQuery.noConflict();
s(document).ready(function () {

<input type="text" class="datepicker">

It is not working. It works fine only when we add local copy of jquery and add reference to it. Due to some reason I cannot use this method.

Now I am trying to achieve this by custom jquery.

var $ = jQuery.noConflict();
$(document).ready(function () {

$(".datemask").keyup(function () {
if ($(this).val().length == 2) {
$(this).val($(this).val() + "/__/____");
} else if ($(this).val().length == 5) {
$(this).val($(this).val() + "/____");

Now as soon as user enter 16 the value becomes 16/__/____ the text cursor is at the end.

Please help me in making this jquery working same as masked input !!!

Answer Source

According to the documentation, jQuery Mask would work with all jQuery versions above 1.7. So please include jQuery library right before you included jQuery Mask plugin. And please consider using one of the public CDNs for the script source rather than its source code address. I usually prefer

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download