Regular expression for entering card code

How can I write a regular expression to match the lines following these rules?

  • 1 letter followed by 4 letters or numbers, then
  • 5 letters or numbers, then
  • 3 letters or numbers followed by a number and one of the following characters :! and @?

I need to allow input as a 15 character string or 3 groups of 5 characters separated by a single space.

I implement this in JavaScript.

+3
source share
4 answers

I won’t write all the regular expression for you, as this is homework, but here are some tips to help you:

  • . [A-Z] . [A-Z] . [0-9] . [A-Za-z0-9].
  • , {n}, [A-Z]{3} 3 .
  • . , % @ #, [%@#], .
  • (, ) : \$ ( $ )
  • ^ $ .
  • \s , , .
  • . , /[a-z]/i, i .
+5

:

/^[a-z][a-z0-9]{4} ?[a-z0-9]{5} ?[a-z0-9]{3}[0-9][!&@?]$/i

0-9 [0-9] \d, .
. ^ $ , , , /i .

+1

.

(, {N}) (, [a-zA-Z])

+1
^[a-zA-Z][a-zA-Z0-9]{4} ?[a-zA-Z0-9]{5} ?[a-zA-Z0-9]{3}[\!\&\@\?]$
0

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


All Articles