javascript - jquery - format yymmdd_hhmmss validation -


i have text input , require user allowed enter numbers "150301_123456" yymmdd_hhmmss format,

how can in jquery auto validate it?

i tried use jquery date picker , jquery number mask plugins don't provide need here.

i doing this:

    $('#aq_utcstart_' + idc).on("keyup", function(val)     {         var value = $(this).val();         var segments = value.split("_");          if (segments.length <= 1)         {             $(this).addclass("inputfatal");                              return false;         }          if (value.indexof("_") < 0 || (segments[0].length < 6 || segments[1].length < 4) ||          (segments[0].length > 6 || segments[1].length > 6))         {                                $(this).addclass("inputfatal");         }         else         {                                $(this).removeclass("inputfatal");         }     }); 

but better, suggestions?

you can use jquery validator regular expression on element want. example of use:

$.validator.addmethod("rulexample", function(value, element){ return /*regular expression*/.test(value);}, "message in case format doesn't fit want");  $('#myelement').validate({ rules: {nameofmyelement:{rulexample:true}} }); 

hope help!


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -