1

I have an input field to search for a blood type, I want to validate it so the accepted value should be only one of these strings (A+, A-, B+, B-, O+, O-, AB+, AB-), so when the user typed any other string an error message should appear, I used the identical option, but it can't compare with more than one field, here is my code:

the identical option:

identical:{                                             

    field: 'a+',                                               

    message: 'not a valid blood type'                                      

},

and here is the a+ field:

<input type="hidden" value="A+" name="a+" />

how I can achieve what I want?

Sparky
  • 98,165
  • 25
  • 199
  • 285
MD.MD
  • 708
  • 4
  • 14
  • 34

1 Answers1

1

You should be able to do this using a regex setting on the validator.

regexp: {
    regexp: /^(A|B|AB|O)[+-]$/,
    message: 'Invalid blood type'
},

The regex is taken from this question: Need help with Regular Expression to Match Blood Group

Community
  • 1
  • 1
ChaoticNadirs
  • 2,280
  • 2
  • 20
  • 27