Check for illegal character combinations with jQuery.Validate -


trying check input on html form ensure not contain &# in string. using jquery.validate http://bassistance.de/jquery-plugins/jquery-plugin-validation , have regex's need check other inputs need ensure 1 field in particular not have & , # together. trick these characters allowed in field, not together. user can put iam&some#test not put iam&#sometest.

this method checking field:

  jquery.validator.addmethod("allowed", function(value, element) {     return this.optional(element) || /^[0-9a-z\-.,:?!@$*&#]+$/i.test(value);      }, ""); 

assume check:

 jquery.validator.addmethod("dissallow", function(value, element) {     return this.optional(element) || /^[&#]+$/i.test(value);  }, ""); 

but checks make sure & , # allowed.

any ideas?

you need check whether 2 consecutive characters part of disallowed group given below

jquery.validator.addmethod("dissallow", function(value, element) {     return this.optional(element) || !(/[&#][&#]/i.test(value)); }, "some rule"); 

demo: fiddle


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -