Regular expression so that only 'a','A','p' and 'P' can be entered as input
Can anyone please tell me regular expression so that only 'a','A','p' and 'P' can be entered as input and at a time only one of those character shoul开发者_如何转开发d be entered?
Thanks in advance.
Here's a simple one: [aApP]
Does that work for you?
You might have to add language-specific start & end line symbols, e.g. ^[aApP]$
if you want to check that the entire input consists only of that one character.
Assuming you want either upper or lowercase p:
[aApP]
^[aApP]{1}$
will match a single 'a', 'A', 'p', or 'P'.
^[aApP]+$
will match one or more 'a', 'A', 'p', or 'P'.
[aApP]
if you only want to match a single character.
^[aApP]+$
to match aa
, PaP
, but not ab
.
精彩评论