Prevent certain words from being typed in a form

I am using the following validation script:  http://formvalidation.io/validators/

I can't seem to find a validator to prevent certain words from being entered.  Am I missing something ?
Is there a small script to validate words like "execute", "run", etc from being entered ?

Maybe this can be done with regexp ?

http://formvalidation.io/validators/regexp/
LVL 1
AleksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
Try item #4 - the "callback" option:
                            callback: function (value, validator, $field) {
                                return ! /\b(execute|run)\b/ig.test(value);
                            }

Open in new window

AleksAuthor Commented:
I tried the code below. I don't get a syntax error, but when I type 'run' in the txtusername field I don't get an alert

Do I just add | for every word I want to prevent the user from typing ?

<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$(document).ready(function() {

    $('#form1').formValidation({
        framework: 'bootstrap',
        icon: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            txtusername: {
                validators: {
                    notEmpty: {
                        message: 'The username is required'
                    },
					
					callback: {
                        message: 'The username cannot contain some words',
                        txtusername: {
                    validators: {
                         callback: function (value, validator, $field) {
                                return ! /\b(execute|run|truncate|shutdown)\b/ig.test(value);
                            }
                     }
 					}
					 }
					 }
            },
			
			txtpassword: {
                validators: {
                    notEmpty: {
                        message: 'The password is required'
                    },
                    
                }
            },
					
  }
		
    });
});
});//]]>  

</script>

Open in new window

hieloCommented:
Do you have a link to your page OR can you post the full HTML you are using?
Price Your IT Services for Profit

Managed service contracts are great - when they're making you money. Yes, you’re getting paid monthly, but is it actually profitable? Learn to calculate your hourly overhead burden so you can master your IT services pricing strategy.

AleksAuthor Commented:
It is an intranet, but here is the relevant code. The form and the validation. The rest of the validation works fine, it doesn't allow the txtusername field to be empty.

          <form action="Index.asp" method="post" name="form1" id="form1" >
               <input name="frmAction" type="hidden" form="form1" value="Submit">
               <div class="form-group">
                    <input name="txtusername" type="text" required class="form-control" id="txtusername" placeholder="username" tabindex="1" title="Please enter a value." value="" maxlength="100">
                  
                </div>
                <div class="form-group">
                    <input name="txtpassword" type="password" required class="form-control" id="txtpassword" placeholder="password" tabindex="2" title="Please enter a value."  value=""  maxlength="25" confirm="">
                </div>
                <input class="btn btn-primary block full-width m-b" name="LogIn_submit" type="submit" id="LogIn_submit" value="Sign In"   tabindex="5">
             
          </form>


AND THIS IS THE VALIDATION CODE:


<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$(document).ready(function() {

    $('#form1').formValidation({
        framework: 'bootstrap',
        icon: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            txtusername: {
                validators: {
                    notEmpty: {
                        message: 'The username is required'
                    },
					
					callback: {
                        message: 'The username cannot contain some words',
                   
                    validators: {
                         callback: function (value, validator, $field) {
                                return ! /\b(execute|run|truncate|shutdown)\b/ig.test(value);
                 
                     	}
 					}
				}
			}
           },
			
			txtpassword: {
                validators: {
                    notEmpty: {
                        message: 'The password is required'
                    },
                    
                }
            },
					
  }
		
    });
});
});//]]>  

</script>

Open in new window

hieloCommented:
You defined it as:
"validators":{"callback":{"message":"...", "validators":{ "callback": function(){...} } }}

That inner validators should not be there.

Try:
<script type="text/javascript">
$(document).ready(function() {

    $('#form1').formValidation({
        framework: 'bootstrap',
        icon: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            txtusername: {
                validators: {
                    notEmpty: {
                        message: 'The username is required'
                    },

                    callback: {
                        message: 'The username cannot contain some words',
                        callback: function(value, validator, $field) {
                            return !/\b(execute|run|truncate|shutdown)\b/ig.test(value);

                        }
                    }
                }
            },

            txtpassword: {
                validators: {
                    notEmpty: {
                        message: 'The password is required'
                    },

                }
            },

        }

    });

});
</script>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
This is great!  Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.