0

I want to validate a string that must be of the format x.xx.xxxxx, the first character is required, followed by a period, then two characters also followed by a period and then another set of characters can be anything of any length

1
  • You might want to check the position of '.' , in your case '.' mush be present at index 1 and 4 according to 0 based indexing.
    – Makarand
    Apr 7, 2021 at 17:37

1 Answer 1

1

I tested out a RegExp pattern /[^.]\.[^.]{2}\.[^.]+/ in the Node console which might help you.

It requires a single non-period character, followed by a period, followed by two non-period characters, followed by a period, followed by one or more non-period characters.

If 0 or more non-period characters are allowed in the last position, then it should instead be as follows, ...

/[^.]\.[^.]{2}\.[^.]*/

> pattern = /[^.]\.[^.]{2}\.[^.]+/
/[^.]\.[^.]{2}\.[^.]+/
> pattern.test('a.bc.d')
true
> pattern.test('a.b.d')
false
> pattern.test('a.bc.djfkflkjd483789374')
true

In the context of yup it looks like this documentation would enable you to use a regexp for validation... https://github.com/jquense/yup#stringmatchesregex-regex-message-string--function-schema

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.