E
E
Erimax2021-06-10 17:40:30
Regular Expressions
Erimax, 2021-06-10 17:40:30

Regular value how to substitute zero?

There is validation in yaml:

mask: '[00000000000000000000]' # 20 цифр
    validators:
      regExp:
        value: "(^$)|(^[0-9]{20}$)" # Регулярное выражение допускает пустую строку или строку из цифр
        message: Номер указан не полностью
      maxLength:
        value: 20
        message: Номер должен состоять из 20 цифр

Something like this is needed:
20 digits or an indication of 0.
All 20 characters at the same time cannot take on the value 0

A validation error occurs if you simply specify 0 (the number is not completely specified).
How to make it possible to put the number 0 in the regular expression? (^$)|(^[0-9]{20}$)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-06-10
@Erimax

You have it in the regular expression - either an empty string, or a string of 20 digits. It is logical that a string of one digit does not fit this regular expression.
^\d{0,20}$

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question