javascript - Jquery validation of string and date -
i want validate 3 input field http://jsfiddle.net/hskat/20/
- only add date
is there regular expression validating this.. dont want use plugins
$('.validate-string').change(function (e) { var valid_str = $(this).val(); ........ });
here 1 method validate string , number.. date have define format want, kindly check below code number , string
$(document).ready(function () { $('.validate-string').change(function (e) { var valid_str = $(this).val(); var regex = /^[a-za-z ]*$/; if (regex.test(valid_str)) { alert("valid"); } else { alert("invalid"); } }); $('.validate-number').change(function (e) { var valid_num = $(this).val(); if(!valid_num.match(/^[0-9,\+-]+$/)){ alert("only numbers allow"); return false; } }); $('.validate-date').change(function (e) { var valid_date = $(this).val(); //yyyy-mm-dd var filter = /^\d{4}-\d{1,2}-\d{1,2}$/; if(filter.test(valid_date)) alert("date"); else alert("not date"); }); }); });
Comments
Post a Comment