vache
vache

Reputation: 341

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

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 characters that are not alphabetic or numeric are inputed

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

Upvotes: 1

Views: 1022

Answers (2)

Nick Craver
Nick Craver

Reputation: 630429

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, ''));
  });
});

Upvotes: 2

Devin Ceartas
Devin Ceartas

Reputation: 4829

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

Upvotes: 0

Related Questions