1

I'd like to use jQuery validation to validate a field that only accepts number and punctuation marks, but there doesn't seem to be a defined rule for it. I've searched google but I've found nothing useful.

Any ideas?

Appreciate your help.

Aslam H
  • 1,669
  • 4
  • 21
  • 46

1 Answers1

3

In the rules object you can do the following:

rules: {
    yourField:{
        regex: /^[0-9!?.;,]+$/
    }
}

You can add the punctuation marks you want to that regex.

callback
  • 3,981
  • 1
  • 31
  • 55
  • I use this cannot type number but letters can, what I expected is only can type a number and punctuation marks sorry I am so bad with regex – Aslam H Mar 18 '18 at 10:43
  • edited the code only number and punctuation marks are allow `/[^0-9!?.;,=<>-+:]+$/` – Aslam H Mar 18 '18 at 12:12