开发者

Stripping non alphabetic and numeric characters before form submit, using jquery

开发者 https://www.devze.com 2022-12-20 04:29 出处:网络
i have an ajax form i know i can use like return str = str.replace(/\\D/g,\'\'); to strip stuff before submit

i have an ajax form i know i can use like

  return str = str.replace(/\D/g,'');

to strip stuff before submit whats the best way to stop form submit when character开发者_StackOverflow中文版s that are not alphabetic or numeric are inputed

my the ajax search form is at vitamovie.com/movies


When submitting, you can run this on the values:

$("#myForm").submit(function() {
  $("input, textarea").each(function() {
    $(this).val($(this).val().replace(/[^a-zA-Z0-9]/g, ''));
  });
});


\D allows only numbers. \W allows only alpha-numeric

0

精彩评论

暂无评论...
验证码 换一张
取 消