0

I need to exclude usage of single quote and double quotes in my textbox. if user enters text with qutation i need to show error. How can i do it with jquery.validate

2 Answers 2

4
$('#elm').validate(
       {
            valid: function(inputValue){
                  return !inputValue.match(/['"]+/);
            }
});
Sign up to request clarification or add additional context in comments.

5 Comments

i dont know how to use it. explain me.
Won't that match if it does have quotes?
Good point alex, changed it. So that plugin lets you validate any input element on the page. The function above tells the plugin to call the anonymous function in order to determine if the element with the id of 'elm' is valid or not. You should replace 'elm' with the id of the element you are validating.
Your regex only needs the character class: /['"]/. There's no need for one or more when one will do. It still works though.
Ur Code is not understandable explain me by using addmethod
0

use regular expression like ^[a-zA-Z] This will accept only Characters from A-Z and a-z.

Here is the code: Add a Method for Regular expression .

         $.validator.addMethod("regex",function(value,element,regexp){
                var re= new RegExp(regexp);
                return this.optional(element) || re.test(value);
            },"Only Characters from A-z");

And then you need to add a rule on that field.

           rules:{
                    username:{
                        required:true,
                        regex:"^[a-zA-Z]+$" //Only Characters
                    }
                 },
           messages:{
                       username:{
                           required:"Mandatory"
                      }
                 },

thats it..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.