Is it possible to create a validation with multiple regex pattern using regula?

450 Views Asked by At

I need to check given text is validate as a wep key. So I need to check all below regular expressions for one field. Is there a way to do that with regula?

^(([0-9A-Fa-f]{10})|)$

^(([\\s\\S]{5})|)$

^(([0-9A-Fa-f]{26})|)$

^(([\\s\\S]{13})|)$

^(([0-9A-Za-z]{58})|)$

^(([0-9A-Fa-f]{24})|)$

[\\s\\S]
2

There are 2 best solutions below

0
Tim Pietzcker On

If you want to check whether a string is a) composed entirely of hexadecimal digits and b) exactly 0, 10, 24, 26 or 58 characters in length (although I don't get what you want with 24 digits), then you can either use

^[0-9a-fA-F]*$

and assert that the length of the match is exactly 0, 10, 24, 26 or 58. Or you can do it in a single regex:

^(?:[0-9a-fA-F]{10}|[0-9a-fA-F]{24}|[0-9a-fA-F]{26}|[0-9a-fA-F]{58})?$
2
FailedDev On

In addition to @Tim's answer :

^(([0-9A-Fa-f]{10})|)$

You realize that this matches also nothing right? And you have this in each and every regex? Why?

Then you have [\\s\\S] which matches everything. It is unclear to me and possibly all others what you are trying to achieve here. Please edit your question.