0

How can I validate the textbox Name does not include '@'?

 rules: {
            Name: {
                required: true,

            },
            Email: {
                required: true,
                email: true
            },
            Password1: {
                minlength: 6
            },
 }
Jude
  • 2,353
  • 10
  • 46
  • 70
  • Validation already implemented by somebody else. I don't want sth like alert box to pop up now. – Jude Mar 05 '14 at 12:58
  • Where is your `HTML` and `JavaScript`? What have your tried to do already? – Pavlo Mar 05 '14 at 13:00
  • 1
    you want something like this http://stackoverflow.com/questions/280759/jquery-validate-how-to-add-a-rule-for-regular-expression-validation – Charles380 Mar 05 '14 at 13:02
  • very unclear question.. to check for a @ symbol, u can just use indexof.. ` if ( $('#textBoxID').val().indexOf('@') == -1) ){ //no @ symbol } ` – JF it Mar 05 '14 at 13:03
  • Already? Nothing. Just thought how to include this in the validate function: ($('#PName').val().indexOf("@@") != -1) – Jude Mar 05 '14 at 13:03

1 Answers1

3

Try the pattern rule

rules: {
    Name: {
        required: true,
        pattern: /^[^@]+$/
    },
    Email: {
        required: true,
        email: true
    },
    Password1: {
        minlength: 6
    },
},
messages: {
    Name: {
        pattern: 'Name should not contain @'
    }
}

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531