I need help with regular expression to match my blood type

I am trying to find a regular expression that will help me check the Blood Group field , which should only accept A [+ -], B [+ -], AB [+ -] and O [+ -].

Here I came up with regex (and tested using Regex Tester ):

[A|B|AB|O][\+|\-]

Now this pattern successfully matches A, B, O [+ -], but does not work with AB [+ -].

Can someone suggest a regex that will serve my purpose?

Thank you t ^ e

+3
source share
5 answers

Try:

(A|B|AB|O)[+-]

, . , , . +- , regexy.

, , , , , :

^(A|B|AB|O)[+-]$

, "helloAB + asdads", .

+16

[] , " ". () :

(A|B|AB|0)(\+|-)
+2

(, (A|B|AB|O)), . , ( ). [-+] , (A|B|AB|O)[-+] "AB+". , (AB|A|B|O)[-+] ( ).

, , : (?:AB|A|B|O)[-+].

, , - , , : ^(?:AB|A|B|O)[-+]$. . ^ , , . , $ , . ( % 100): \A, \Z \Z. , \A , \Z , \Z .

+2
source

^ (A | B | AB | O) [+ -] $? This will give the correct result.

0
source

For the case insensitive to the html pattern attribute, you can try this

([AaBbOo]|[Aa][Bb])[\+-]


<input type="text" maxlength="3" pattern="([AaBbOo]|[Aa][Bb])[\+-]" required />
0
source

Source: https://habr.com/ru/post/1710658/


All Articles