Jquery :: Validation Rules AddMethod - PHP Filter For Form

Feb 22, 2011

I have created a php filter for a form that returns an error message if someone uses profanity in the comments field and makes them redo that field before inserting into a database. Here is the code I use for that (I have omitted the lengthy list of profanity..):

Code:
if (isset($_POST['comments'])){
$comments = $_POST['comments'];
$filter=array("badword1", "badword2");
for ($i = 0; $i < count($filter); $i++) { .....
if (preg_match("/".$filter[$i]."/i", $comments)) {
$profanity_msg="Profanity is not allowed";
}}}
//Then this before the form
if(isset($profanity_msg)){
echo $profanity_msg;
}

However, the rest of my form is validated through JQuery Validator and I would like to make a rule that would do the filtering instead of relying on the php. Here is a sketch of what I think I will need to do to build the custom rule, but I am not sure how to write the equivalent function to my php code above.

Code:
$(document).ready(function(){
//custom validation rule - profanity
$.validator.addMethod("profanity",
"Equivalent of my php function goes here..."
);
//validation implementation will go here.
$("#TestForm").validate({
rules: {
comments: {
required: true,
profanity: true
}},
messages: {
comments: {
required: "* Required",
profanity: "* No Profanity Allowed"
}}});
})

View 1 Replies


ADVERTISEMENT

JQuery :: Validation Dynamic Rules - Add In Rules Dynamically Through The Rules(add) Function After Adding Some Dynamic Fields Through The User Inputs

Sep 6, 2011

I will like to know if there is anyway to view all the rules that I have currently in the Jquery validation plugin. Currently, I am trying to add in rules dynamically through the rules(add) function after adding some dynamic fields through the user inputs. the rules are added in this manner.

[Code]...

View 2 Replies View Related

JQuery :: Validation: Form With Multiple Submit Buttons Having Different Validation Rules

Oct 2, 2009

I have a form with multiple fieldsets which are visible conditionally. There are three submit buttons "Abandon", "Save" and "Save & Continue". Each button should validate specific controls of the form and submit it. I tried setting "onsubmit: false" and checking for "$('#myForm').valid ()" on click of these buttons., but that validates all controls of the form.

View 1 Replies View Related

JQuery :: Converting Click Function To AddMethod Validation Rule For Jquery.validation

Jul 13, 2010

I have the following code that validates a credit card expiration date, from 2 separate select boxes as being valid. changing this to an addMethod for the validation plug in. I have one that works as validating input from a text input, but would like to understand this method when applied to values of select boxes. Code for change function

[Code]...

View 6 Replies View Related

JQuery :: Validation Plugin, Changing Message With AddMethod

May 18, 2010

I've written my own custom validation method using addMethod which works great. But what I'd like to do is change the error message depending on which part of the validation it fails on.

I've tried defining & using a var for the message but the message never changes, a very simple cut-down example:

var customError = "";
$.validator.addMethod("myvalidator", function(value, element) {

[Code]....

View 4 Replies View Related

JQuery :: Dynamic Inputs Targeting For Validation Rules?

May 6, 2011

I'm working on the validation plugin for jquery and trying to figure out how I can target the text boxes that are dynamically generated with this change event. I'm trying to target them so I can set up rules for my page.

[Code]...

View 11 Replies View Related

JQuery :: Validate Remove All Rules / Disable Validation?

Aug 22, 2011

I'm using the validation plugin and I have a lot of rules set on my page [code]...

My question, how can I disable all the rules or the entire validation ? I can submit the form via two buttons to either save the page (here I need validation) or "delete" the current view (here I do not want any validation)

View 4 Replies View Related

Jquery :: Writing An "addMethod" For Validation Plugin?

Nov 3, 2009

It's very simple (two lines at most) for someone that knows what they're doing. I posted all the details (and code) here [URL].

View 5 Replies View Related

JQuery :: Validation Plugin - Adding Dynamic Custom Rules

Jan 26, 2011

Im using the jquery validation plugin: [URL] The forms are generated dynamically using php, with the standard class 'required' the plugin looks for, however when it comes to adding my custom rules i want them to be dynamic, as the name/id attributes are generated based on what the id of the form is: i.e. the form ID is #comp so an input would have a name attribute of comp_forename, comp_surname so basically the validator is initiated by looking in the body for a form: var form_id = $('body form').attr('id'); Then how can icancatante the strings to created the name attributes dynamically in the rules here:

[URL]

View 1 Replies View Related

JQuery :: Variable Validation Rules For Same Input Field Depending On Other Fields

May 30, 2009

I have the following html, field xxx requires a number from 0 to 100 when percentage is selected, and 0 to inifinity when dollar is selected.what's the best practice to setup validation for this?the key is to control the maximum value.I have tried depends expression in a max rule, but it doesn't seem that it can satisfy my requirement.

View 1 Replies View Related

How To Add Validation Rules For Radio Buttons

Jun 18, 2010

In "validateField" function radio is not exists and I don't know how can I add a validation rule for radio buttons. My code is attached.

View 1 Replies View Related

Jquery :: Re-validate A Validated Form After Checkbox Changed With Different Rules?

Sep 1, 2010

I am trying to validate a form with a couple of elements being required if a checkbox is NOT checked. Now if I submit the form the rules fire - and then I check the checkbox on - the validation rules have already fired - and even though the checkbox is now checked - the validation rules still apply and the form will not submit until I enter the fields.What I was hoping was that the checkbox could toggle the rules on or off.

var validator = $(".cmxform").validate({
rules: {
txtAddress1: {

[code]....

View 1 Replies View Related

OnClick And OnKey - How To Handle Form Rules

Sep 16, 2011

Here's the JS:
HTML Code:
$("#select_2").hide();
$("#select").click(function(){
if ($("#option_1").not(":selected")){
$("#select_2").hide();
}
if ($("#option_1").is(":selected")){
$("#select_2").show();
}});

The HTML goes something like
HTML Code:
<select id="select">
<option value="something">something</option>
<option value="something else">something else</option>
<option id="option_1" value="option_1">OPTION 1</option>
</select>

<select id="select_2">
<option value="something">something</option>
<option value="something else">something else</option>
</select>

I have a form that shows a drop down of choices. If the user selects 'OPTION 1' from the list, they are shown another drop down with more choices. The second drop down is hidden by default and shown only if 'OPTION 1' is selected. This works fine when using the mouse, but the user can tab to this field, choose 'OPTION 1', and the next field does not show because of my onclick event handler. Is there a way I can look for either the keyboard or the mouse?

View 3 Replies View Related

JQuery :: Use An "onSuccess" Method "rules" In Validation?

Apr 15, 2011

How to use an "onSuccess" method or something similar for "rules" in JQuery validation?

How it would work here.

View 1 Replies View Related

JQUERY :: More Sophisticated Validating Rules - Validating Form Plug

Mar 21, 2010

I am using a validating form plug in for jquery and I have a question about it. Let this function will be an ex.:

[Code]....

'e' is the name attribute of one form element, but can I choose more elements using jquery (CSS) rules like this: input[name*=e] or how can I do something similar?

View 5 Replies View Related

Jquery :: Display Validation Error Messages When Form Validation Fails

Apr 1, 2011

I am trying to display validation error messages when form validation fails. Currently it does display the error messages but then disappears straight away. How can I stop the page from refreshing when validation fails? I have return false in my code when validation fails but still having same problem. Currently I have only done the validation for the full name only. The error msg is showed in:

[Code]...

View 2 Replies View Related

JQuery :: Form Validation Plugin: Customize Input Validation?

Jun 21, 2009

This is in regards to Jrn Zaefferer's plug in.How do you customize input validation so that I can remove foullanguage?So that first name or last name doesn't have "fck you" or something

View 2 Replies View Related

JQuery :: Validation Plugin - Submit Form Without Validation?

Jul 19, 2009

I'm using the Validation plugin for JQuery and was wondering if there was a function to submit the form without causing it to validate the form. I have a table with a list of radio-buttons and above that is a drop down list of states. The drop down list of states is used to filter the table rows and when the selected item changes it posts-back to the server (via $("#frm").submit()). I don't want this to cause any validation to occur. Is there another function I can call besides submit(), or some other method?

View 1 Replies View Related

JQuery :: Validate Plugin - Addmethod('math') For A Numeric Verification

Oct 6, 2010

I hardly try to use a method i added

Here is the code:

I added this code between $(document).ready(function(){ and $("#commentform").validate();

In my form i have:

I try to use the new method math in order to display an addition in the label and the result have to be typed in the input, but i fail.

View 3 Replies View Related

JQuery :: Transforming Change Function To Validator AddMethod Rule

Jul 12, 2010

I wrote this function to be a change event applied to a checkbox. Now it is apparent I need to use it as a custom validator method, so it runs when you hit "Next" to step through the form. I have all that working, I just can't get the syntax of the rule right.

Here it is as a change event:
$(
'#MKDPT'
).change(
function(){
if(
$(
'#MKDPT'
).is(
':checked'
)){
var
checked
=
false
; .....

And my attempt at a custom validation rule:
$
.
validator
.
addMethod (
"MKDPTOnly" ,
function (
value .....

I have tried several versions, but none is letting the form go to the next step (return true) if the conditions are met.

View 7 Replies View Related

Form Validation - Multiple Input Field Validation?

Dec 21, 2009

I need to validate two forms containing multiple input fields but want just one error message if any of the fields are left blank, the page is required to submit the users details (registration form). Also if any of these fields are left blank i don't want to be able to go to the next page on clicking the submit button

View 1 Replies View Related

JQuery :: Checkbox Rules Overlapping ?

Jul 15, 2010

I have 2 checkbox rules that are overlapping.

This one runs first

This one runs second:

So basically the first one runs if BMFNP is checked, and INTEF isn't it checks INTEF and runs the alert. At that time, both are checked so it runs the second function. How can I fix this? I need both to work and display different messages for each situation, if BMFNP is checked, INTEF isn't check INTEF and alert it has been added and BMFNP can only do xxxxx. If both are checked, simply alert that BMFNP can only do xxxx, no need to alert it has been added.

View 2 Replies View Related

JQuery :: Validate() : Assign Rules By Using ID?

Sep 20, 2010

I tried to understand how the pugin works, and I create that code :

$().ready(function() {
$("#TargetEditForm").validate({
rules: {

[code]....

View 1 Replies View Related

JQuery :: Remove Rows From Tables According To Some Rules?

Aug 18, 2009

I have a table like this:

<table>
<tr class="item_collection_begin">
<td colspan="3"></td>
</tr>

[Code]....

To sum it up I have a rows that acts a header for a collection of item (class="item_collection_begin). Is there some way to click on a button and then all the items and their header (item_collection_begin), and their footer (item_collection_end, this is not mandatory that they have such one) are all hidden if there is no item in the collection where the cell (amount) is bigger than zero? I have got it to work for all the rows with items: $('#test .amount').filter(function (index) { return $(this).html() == 0; }).parent().remove(); But this does not hide item_collection_begin (and perhabs item_collection_end).

View 1 Replies View Related

JQuery :: Validate - Setting Rules Based On ID Instead Of Name?

Mar 31, 2010

I apologize for posting again - Joern, the developer who built this plugin made a suggestion but I never heard back on a follow up question. I am using validate on a fairly big project. The problem I'm running into is that our e-commerce environment is writing a fairly cumbersome value into each input's name field. It's basically pointing to the form handler. This itself makes it difficult to build rules because the name attribute can be 100 characters long. It's also possible that the path to the form handler will change which is troublesome.

The ideal solution is to have set the validation rules and messaging on the id of the input. Joern indicated that this would be possible, but I need some help going about it.

View 1 Replies View Related

JQuery :: Validator Plugin Rules And Events?

May 21, 2011

how to specify the event in the rule?For example I create a rulejQuery.validator.addMethod("greaterThanZero", function(value, element) { return his.optional(element) || (parseFloat(value) > 0); }, "* Amount must be greater than zero");Iattach this rule to the form$('form').validate({ rules : { amount : { greaterThanZero : true } } });how can I specify when this rule should be checked , for example onChange oronKeypress or when another field is edited. Is it possible to do this as a form validate rule?

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved